This cordova plugin allows you to play background audio. Media player plays audio or (audio only) video files even your application goes to background.
This plugin creates window.plugins.BgPlayer object to use these functions.
Warning This plugin uses Cordova Vitamio Plugins player to play media for some advantages. But you can easily change with removing import statement at PlayerService.java.
plays the given file. This comman also create a notification. If service already playing a different file, firstly stop service and recreate to play.
stops service and remove the notification.
returns is any file playing.
returns actively playing file path.
fires when call play method
fires when satart playing media
fires when call stop method.
fires when goes some thing wrong. media url is not correct, no internet access, unspoorted codec etc.
window.plugins.BgPlayer.onplay = function () {
console.log("loading....");
}
window.plugins.BgPlayer.onStartPlaying = function () {
console.log("now playing la la la...");
}
window.plugins.BgPlayer.onstop = function () {
console.log("that is all folks. go home now.");
}
window.plugins.BgPlayer.onfailure = function (error) {
console.log("oh no no no. error is " + error);
}
if (window.plugins.BgPlayer.isPlaying()){
var playingMedia = window.plugins.BgPlayer.getPlayingMediaUrl();
console.log("yes i am the player. player is play this file: " + playingMedia);
}
else
window.plugins.BgPlayer.play("http://www.www.com/www.mp3", {
"title": "I am the title",
"text": "So I am the text too"
});
setTimeout(function () {
// I will listen yout only 5 seconds, sorry
window.plugins.BgPlayer.stop();
}, 50000);