html5 - Audio will not play on Android using phonegap, but works fine on iOS -


it works fine on ios.

i have looked many answers including these 2:

play sound on phonegap app android

html5 audio not playing in phonegap app (possible use media?)

i have tried of solutions:

  • changing path /android_asset/www/ android
  • using .ogg files
  • pre load audio play() / pause().
  • using media plugin provided cordova/phonegap

here current code:

if(device.platform === "android")   //different path android {     url = "/android_asset/www/sound.ogg"; }else{     url = "sound.mp3"; } alert(url); sound = new media(url); sound.play(); 

anyone have ideas?? feels have been going round in circles

i had similar , solution worked me complete path of application using window.location.pathname, way dont need worry device type, give complete path including index.html , using below function strip off index.html string , append media file.

function getphonegappath() {  var path = window.location.pathname; path = path.substr( path, path.length - 10 ); //strip off index.html return 'file://' + path;  }; 

and

url = getphonegappath()+'sound.ogg';  //or mp3   alert(url); sound = new media(url); sound.play(); 

hope helps


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -