简体   繁体   中英

Playing audio in Android Cordova Project without using the media plugin

I have two questions regarding the audio play on android device while using the cordova. 1. Can I play the audio in android cordova project without using the cordova media plugin using this code ?

var audio = new Audio('swoosh.mp3');
audio.play();

I'm getting this eroor : E/MediaPlayer﹕ Error (1,-2147483648) when trying to do this

  1. I have used Cordova media plugin and it works only once in a page when calling the audio function on onload

     function playmusic() { var url1 = "/android_asset/www/swoosh.mp3"; var fall_media = new Media(url1, // success callback function () { console.log("playAudio():Audio Success"); }, // error callback ); fall_media.play(); } <body onload="playmusic();"></body> 

Why this happens? Any help will be appreciated.

  1. You can, but you are going to be writing a lot of custom code to do what is already provided for you. Especially if you are using other platforms besides Android. You also will increase the size of your application because you will have to provide each different format for each different device.

  2. Yes that would be correct. The only time you are running this function is onload. If you are looking to use a button for this you could create an event for a particular button and play it that way. Take a look at the documentation and you'll see a full featured example. Sorry, I tried to paste the relevant parts here, but for some reason it was stripping code out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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