Hi,
I’m trying to play audio in my application on android device. I’ve tried cordova media plugin but keeps getting error “Media not defined”, no matter how i tried both on browser and device.
So i’m looking for something new, is there a media plugin that’s actually working ? what are you guys use to play audio ?
Thank you.
Hi flameloki,
For me, this plugin works well.
Plugin work only on device and emulator, not on browser.
Beware to the url or the audio file is located.
function getMediaURL(s) {
if (device.platform.toLowerCase() === ‘android’) { return ‘/android_asset/www/audio/’ + s; }
if (device.platform.toLowerCase() === ‘ios’) { return ‘/ios/www/audio/’ + s; }
}
Thank you for your reply,
I am trying to play remote audio not in local file. I am using ionic lates beta 14 and tried on device already but no sound comes out
Update
this code works tho
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
document.querySelector("#playMp3").addEventListener("touchend", playMP3, false);
};
$scope.play = function (){
//var mp3URL = getMediaURL("sound/music.mp3");
var mp3URL = 'http://translate.google.com/translate_tts?tl=ja&q=testingsoudi';
var media = new Media(mp3URL, null, mediaError);
media.play();
}
function getMediaURL(s) {
if(device.platform.toLowerCase() === "android") return "/android_asset/www/" + s;
return s;
}
function mediaError(e) {
alert('Media Error');
alert(JSON.stringify(e));
}
but when playing local audio it returning “media error code 1”
Media error code 1, for me, means it does not find the file.
yep, i forgot we need to add android asset on the file path