gpt4 book ai didi

android - 显示广告时,Android上的声音消失

转载 作者:行者123 更新时间:2023-12-03 00:08:44 26 4
gpt4 key购买 nike

当我的角色越过终点线时,我会播放“胜利”声。我有一个 AudioSource 对象,我将其简单地称为 PlayOneShot 并将其传递给我的 AudioClip 作为:

public void PlayWon() {
if (GameData.Data.Settings.SoundsOn) {
AudioSource audio = GetComponent<AudioSource>();
audio.Stop();
audio.PlayOneShot(WinSound);
}
}

我对 AudioSource 的设置是:

enter image description here

并将其附加到的对象加载到永不破坏的 Loader 场景中。我可以通过以下方式确保这一点:
DontDestroyOnLoad(this);

在醒着。

我的声音可以在iOS,iPhone和iPad上正常播放。但是,在我的Samsung Galaxy Tab S上进行测试时,声音会播放,然后暂停,同时显示插页式广告,然后关闭该声音,声音就会继续。我正在使用Chartboost和Admob并使用基本调用:
    if (Chartboost.hasInterstitial(CBLocation.LevelComplete)) {
Debug.Log("Showing CB Ad");
Chartboost.showInterstitial(CBLocation.LevelComplete);
}
else if (_admobInterstitial.IsLoaded()) {
Debug.Log("Showing Admob Ad");
_admobInterstitial.Show();
}
else {
Debug.Log("Neither cached, trying CB again");
Chartboost.cacheInterstitial(CBLocation.LevelComplete);
Chartboost.showInterstitial(CBLocation.LevelComplete);
}

有什么想法为什么我的声音会在此设备上消失吗?我没有其他Android设备可以对其进行测试,但我认为这是与Android相关的问题。声音在Chartboost和Admob上均消失。

谢谢

最佳答案

您可以使用协程播放声音。协程完成后,您可以展示广告。

private IEnumerator PlaySoundAndShowAd()
{
//play sound
yield return new WaitForSeconds(1.0f)
//show ads or do something.
}

关于android - 显示广告时,Android上的声音消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34405260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com