简体   繁体   English

使用Cordova Media插件时出现问题

[英]Issue in using Cordova Media plugin

I am developing an Android app using Ionic framework. 我正在使用Ionic框架开发Android应用程序。 In there I have used Cordova Media Plugin to play some mp3 files. 在那里,我使用Cordova Media Plugin播放一些mp3文件。

There is something strange happening in the code that I cannot understand. 代码中发生了一些奇怪的事情,我无法理解。 In the code I have a function to create a media object and play it as: 在代码中,我有一个创建媒体对象的功能,并将其播放为:

function playAudio(src) {
  myMedia = new Media(src, onSuccess, onError);
  myMedia.play();
  document.getElementById('forTest2').innerHTML = "end of playAudio";
}

In my JavaScript code I have this code section: 在我的JavaScript代码中,我有以下代码部分:

document.getElementById('forTest1').innerHTML = "before playAudio";
playAudio(audioSrc);
document.getElementById('forTest3').innerHTML = "visited after playAudio return"; 

I have added document.getElementById lines for debug. 我已经为调试添加了document.getElementById行。

When I run the code I see the following lines shown in the document screen: 当我运行代码时,我看到文档屏幕中显示的以下行:

before playAudio
end of playAudio

I expected after returning from the playAudio function to see these 3 lines instead of above 2 lines: 我期望从playAudio函数返回后看到这3行而不是2行以上:

before playAudio
end of playAudio
visited after playAudio return

But I do not see the visited after playAudio return message, which shows we do not return from the playAudio(audioSrc); 但是我没有看到visited after playAudio return消息visited after playAudio returnvisited after playAudio return ,这表明我们没有从playAudio(audioSrc);返回playAudio(audioSrc); , which is strange. ,这很奇怪。

Is there any explanation for this? 这有什么解释吗?

I am testing this on Android API 18 if it matters. 如果重要的话,我正在Android API 18上进行测试。

Any help is really appreciated. 任何帮助都非常感谢。

Are you sure, that you have an element with id forTest3 ? 你确定你有一个id为forTest3的元素吗? because it makes no sense, that end of playAudio function is reached and then the next instruction isn't executed. 因为没有意义,达到playAudio函数的结尾然后不执行下一条指令。 It looks more like there is no element forTest3 它看起来更像是没有forTest3元素

Try to use console.log() instead. 尝试使用console.log()代替。

function playAudio(src) {
  myMedia = new Media(src, onSuccess, onError);
  myMedia.play();
  console.log("end of playAudio");
}

console.log("before playAudio");
playAudio(audioSrc);
console.log("visited after playAudio return"); 

What happen if you add some additional outputs? 如果添加一些额外的输出会发生什么?

myMedia = new Media(src, onSuccess, onError, function(status){console.log(status)};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM