我的问题:
我使用 Cordova 的媒体类。MP3 文件只播放一次(第一次)。
代码:
将此代码添加到 Cordova Starter 项目以重现我的问题:
var playCounter = 0;
function playMP3(){
console.log("playMP3() counter " + playCounter);
var my_media = new Media("app/www/test.mp3");//ressource buildAction == content
my_media.play();
playCounter++;
}
[...]
<p onclick="playMP3();">Click to Play MP3</p>
VS输出:
[...]
GapBrowser_Navigated :: /app/www/index.html
'UI Task' (Managed): Loaded 'System.ServiceModel.Web.dll'
'UI Task' (Managed): Loaded 'System.ServiceModel.dll'
Log:"onDeviceReady. You should see this message in Visual Studio's output window."
'UI Task' (Managed): Loaded 'Microsoft.Xna.Framework.dll'
Log:"playMP3() counter 0"
'UI Task' (Managed): Loaded 'System.SR.dll'
Log:"media on status :: {\"id\": \"fa123123-bc55-a266-f447-8881bd32e2aa\", \"msg\": 1, \"value\": 1}"
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
Log:"media on status :: {\"id\": \"fa123123-bc55-a266-f447-8881bd32e2aa\", \"msg\": 1, \"value\": 2}"
Log:"media on status :: {\"id\": \"fa123123-bc55-a266-f447-8881bd32e2aa\", \"msg\": 2, \"value\": 2.141}"
Log:"media on status :: {\"id\": \"fa123123-bc55-a266-f447-8881bd32e2aa\", \"msg\": 1, \"value\": 4}"
Log:"playMP3() counter 1"
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.IsolatedStorage.IsolatedStorageException' occurred in mscorlib.dll
Log:"media on status :: {\"id\": \"2de3388c-bbb6-d896-9e27-660f1402bc2a\", \"msg\": 9, \"value\": 5}"
我的配置:
- 科尔多瓦-1.6.1.js
- 卢米亚 800
- WP 7.5 (7.10.7740.16)
解决方法(种类):
- 停用应用程序(关闭屏幕)
- 重新激活应用程序(打开屏幕)
- -> 你再拍一张。
欢迎任何帮助,因为我从五月开始就被阻止了,而且我在任何地方都找不到有用的信息。
另外,你能告诉我这段代码是否适用于你的配置吗?
.
.
.
更新:添加演示代码,Cordova 1.8.0rc1
使用全局变量。保持实例存活。
结果
- test2.mp3 播放完毕,可以正常回放。
- test.mp3 根本没有播放。
- 这是您播放的第一个文件。
代码
function onDeviceReady()
{
document.getElementById("welcomeMsg").innerHTML += "Cordova is ready! version=" + window.device.cordova;
console.log("onDeviceReady. You should see this message in Visual Studio's output window.");
my_media = new Media("app/www/test.mp3");//ressource buildAction == content
my_media2 = new Media("app/www/test2.mp3");//ressource buildAction == content
}
var playCounter = 0;
var my_media = null;
function playMP3(){
console.log("playMP3() counter " + playCounter);
my_media.play();
playCounter++;
}
var my_media2 = null;
function playMP32(){
console.log("playMP32() counter " + playCounter);
my_media2.play();
playCounter++;
}
</script>
[...]
<p onclick="playMP3();">Click to Play MP3</p>
<p onclick="playMP32();">Click to Play MP3 2</p>
VS输出:
Log:"onDeviceReady. You should see this message in Visual Studio's output window."
INFO: startPlayingAudio could not find mediaPlayer for 71888b14-86fe-4769-95c9-a9bb05d5555b
Log:"playMP32() counter 0"
INFO: startPlayingAudio could not find mediaPlayer for 71888b14-86fe-4769-95c9-a9bb05d5555b
Log:"playMP32() counter 1"
Log:"playMP3() counter 2"
INFO: startPlayingAudio could not find mediaPlayer for b60fa266-d105-a295-a5be-fa2c6b824bc1
A first chance exception of type 'System.ArgumentException' occurred in System.Windows.dll
Error: El parámetro es incorrecto.
Log:"playMP32() counter 3"
INFO: startPlayingAudio could not find mediaPlayer for 71888b14-86fe-4769-95c9-a9bb05d5555b
.
.
.
更新:科尔多瓦 2.0.0
我用 2.0.0 的测试用例更新了 Apache 错误报告。
任何人都可以重现这个吗?