Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issues 8940 #14808

Merged
merged 3 commits into from
Jul 2, 2024
Merged

Conversation

zhefengzhang
Copy link
Contributor

Re: 8940

This problem only occurs on mobile devices (currently only Android phones have this problem) because it takes longer to load Audio resources on mobile devices than on computers.
The problem is that the loaded state of audioClip cannot be set directly when setting _nativeAsset, but should be set in the execution callback after the native resource is actually loaded, otherwise the audio will not be played when you click play for the first time on the mobile device. The engine is modified as follows:

因为在手机设备上加载 Audio 资源所需要的时间比在电脑上来得长,所以此问题只有出现在手机设备上。
问题原因是 audioClip 的 loaded 状态不能在设置 _nativeAsset 时就被直接设置,而应该是在原生资源真正被加载完成后的执行回调里设置,否则会导致在手机设备(目前只有 Android 手机会有此问题)上第一次点击播放时无法播放音频。引擎修改方法如下:

图片

图片

@shrinktofit shrinktofit reopened this May 16, 2023
@minggo minggo requested a review from bofeng-song May 24, 2023 09:41
@@ -127,6 +127,7 @@ var AudioClip = cc.Class({
let self = this;
cc.assetManager.postLoadNative(this, function (err) {
self._loading = false;
self.loaded = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check the value of err, if err has a value it means an error occurred, probably due to a problem with resource loading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added code to check the err parameter

@@ -78,7 +78,7 @@ var AudioClip = cc.Class({
this._audio = value;
}
if (this._audio) {
this.loaded = true;
// this.loaded = true;
this.emit('load');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should delay load event to the callback too, also need to check whether this modification cause issue in web and mini game platforms

@zhefengzhang zhefengzhang changed the base branch from v2.4.12 to v2.4.15 July 2, 2024 03:00
@minggo minggo merged commit 73ed227 into cocos:v2.4.15 Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants