Spielen Sie MP3-Medien mit phonegap/Cordova

Mein problem:

Ich benutze den Media Klasse von Cordova.
Die MP3-Datei nur einmal gespielt (das erste mal).

Code:

Fügen Sie diesen code in der Cordova-Starter-Projekt zu reproduzieren mein 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}"

Meine Config:

  • cordova-1.6.1.js
  • Lumia 800
  • WP 7.5 (7.10.7740.16)

WorkAround (Art):

  • Desaktivieren Sie die app (den Bildschirm auszuschalten)
  • reaktivieren der app (schalten Sie den Bildschirm)
  • -> Sie erhalten eine weitere Chance.

Jede Hilfe ist willkommen, da ich gesperrt bin auf diesem seit Tagen, und ich fand keine nützliche information überall.

Auch, Können Sie mir sagen, ob dieser code funktioniert auf Ihrem config ?

.

.

.

Update: fügen Sie einen demo-code, Cordova 1.8.0rc1

mithilfe einer globalen var. Halten Sie die Instanz am Leben.

Ergebnis

  • Die test2.mp3 gespielt wird, und kann die Wiedergabe in Ordnung.
  • den test.mp3 ist nicht überhaupt gespielt hat.
  • Es ist die erste Datei, die Sie spielen, das wird funktionieren.

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

.

.

.

Update: Cordova-2.0.0

Ich die aktualisierten Apache bug-report mit einem Testfall für die 2.0.0.

Kann jemand reproduzieren ?

link zu bug-Bericht:
https://issues.apache.org/jira/browse/CB-941

  • Ich habe versucht, mit die Letzte version (1.8 rc1) von GitHub. Gleiche problem.
  • Hinweis: das problem ist das gleiche mit dem 1.8, aber die Fehler sind differents.
  • Wenn Sie kümmern sich um die Ausgabe habe ich davon berichtet, das von Apache : issues.apache.org/jira/browse/CB-941
InformationsquelleAutor Loda | 2012-06-03
Schreibe einen Kommentar