WP7: play MP3 using Media with phonegap/Cordova
Posted
by
Loda
on Stack Overflow
See other posts from Stack Overflow
or by Loda
Published on 2012-06-03T10:38:53Z
Indexed on
2012/06/26
21:16 UTC
Read the original article
Hit count: 289
My problem:
I use the Media Class from Cordova. The MP3 file is only played once (the first time).
Code:
Add this code to the Cordova Starter project to reproduce my problem:
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 output:
[...]
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}"
My Config:
- cordova-1.6.1.js
- Lumia 800
- WP 7.5 (7.10.7740.16)
WorkAround (kind of):
- Desactivate the app (turn off the screen)
- reactivate the app (turn on the screen)
- -> you get one more shot.
Any help is welcome as I am blocked on this since may days and I found no usefull information anywhere.
Also, Can you tell me if this code work on your config ?
.
.
.
Update: add a demo code
using a global var. Keeping the instance alive.
result
- The test2.mp3 is played and can replay fine.
- the test.mp3 is not played at all.
- It is the first file you play that will work.
Code
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 output:
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
Can anybody reproduce this ?
link to bug report: https://issues.apache.org/jira/browse/CB-941
© Stack Overflow or respective owner