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

fix cc.sys.os && audio downloading on Alipay iOS #30

Merged
merged 2 commits into from Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/engine/Loader.js
Expand Up @@ -83,7 +83,7 @@ function downloadImage (item, callback, isCrossOrigin) {

function downloadAudio (item, callback) {
if (cc.sys.__audioSupport.format.length === 0) {
return new Error(debug.getError(4927));
return new Error(cc.debug.getError(4927));
}

var dom = document.createElement('audio');
Expand Down
8 changes: 5 additions & 3 deletions common/engine/globalAdapter/BaseSystemInfo.js
Expand Up @@ -14,13 +14,15 @@ let systemInfo = {
sys.languageCode = env.language.toLowerCase();
var system = env.system.toLowerCase();

if (env.platform === "android") {
let platform = env.platform;
platform = platform.toLowerCase();
if (platform === "android") {
sys.os = sys.OS_ANDROID;
}
else if (env.platform === "ios") {
else if (platform === "ios") {
sys.os = sys.OS_IOS;
}
else if (env.platform === 'devtools') {
else if (platform === 'devtools') {
sys.isMobile = false;
if (system.indexOf('android') > -1) {
sys.os = sys.OS_ANDROID;
Expand Down
28 changes: 27 additions & 1 deletion platforms/alipay/wrapper/engine/Loader.js
Expand Up @@ -7,4 +7,30 @@ cc.loader.downloader.loadSubpackage = function (name, completeCallback) {
loadedSubPackages[name] = true;
}
completeCallback && completeCallback();
};
};

function downloadAudio (item, callback) {
if (cc.sys.__audioSupport.format.length === 0) {
return new Error(cc.debug.getError(4927));
}

let audio = my.createInnerAudioContext();
audio.onCanPlay(() => {
callback(null, audio);
});
audio.onError(() => {
callback(new Error('load audio failed ' + item.url), null);
});
audio.src = item.url;
Copy link
Contributor

Choose a reason for hiding this comment

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

直接返回audio没事的吧?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

没问题,最终只是取 audio.src
downloader 阶段只是在底层生成一份缓存

}

// FIX audio downlaod error on Alipay iOS 10.1.78
if (cc.sys.os === cc.sys.OS_IOS) {
cc.loader.downloader.addHandlers({
Copy link
Contributor

Choose a reason for hiding this comment

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

这里执行是在common里面loader之后?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

对,会覆盖 common 的逻辑

// Audio
mp3 : downloadAudio,
ogg : downloadAudio,
wav : downloadAudio,
m4a : downloadAudio,
});
}