Hello, I have the following code to play a local mp3 file in iOS and Android.
This works fine in iOS but not in android. What am I missing?
var mediasrc = $ionicPlatform.is('ios') ? "sounds/blop.mp3":"/android_asset/www/sounds/blop.mp3";
media = $cordovaMedia.newMedia(mediasrc);
// and then much later, when I receive a push notification
// I do a media.play() if mode is foreground
Here are my locations for blop.mp3 after ionic build android and ionic build iOS
$ find . -name blop.mp3
./platforms/android/assets/www/sounds/blop.mp3
./platforms/android/build/intermediates/assets/armv7/debug/www/sounds/blop.mp3
./platforms/android/build/intermediates/assets/armv7/release/www/sounds/blop.mp3
./platforms/android/build/intermediates/assets/x86/debug/www/sounds/blop.mp3
./platforms/android/build/intermediates/assets/x86/release/www/sounds/blop.mp3
./platforms/android/build/intermediates/res/armv7/debug/raw/blop.mp3
./platforms/android/build/intermediates/res/armv7/release/raw/blop.mp3
./platforms/android/build/intermediates/res/x86/debug/raw/blop.mp3
./platforms/android/build/intermediates/res/x86/release/raw/blop.mp3
./platforms/android/res/raw/blop.mp3
./platforms/ios/build/emulator/zmNinja.app/www/sounds/blop.mp3
./platforms/ios/www/sounds/blop.mp3
./www/sounds/blop.mp3
Okay, I fixed it - also, I forked a version that disables all the crazy android permissions the default version needs just to play a media file - no additional permissions are needed if all you want to do is play a small media file while in foreground, which was my need
Duovili
September 5, 2016, 11:49am
3
How did you resolve this bug? I am struggling with the same issue.
I don’t remember what I did differently, but my code is open:
How I defined the media path:
return;
}
console.log (">>>>>>>>>>>>>>>>>EVENT SERVER SENDING: type="+type+" DATA="+JSON.stringify(obj));
ws.send({
'event':type,
'data': obj
});
/*if (ws.$status() == ws.$CLOSED)
{
NVRDataModel.log("Websocket was closed, trying to re-open");
ws.$un('$open');
//ws.$on ('$open', openHandshake);
ws.$open();
ws.$on('$open', openHandshake, function()
{
//console.log(" sending " + type + " " +
// JSON.stringify(obj));
How I play local media:
Copying media to the right place before build:
# exe cp www/external/GCMIntentService.java platforms/android/src/com/adobe/phonegap/push
#else
# echo "Directory plugins/phonegap-plugin-push/src/android/com/adobe/phonegap/push/ does not exist, skipping..."
#fi
echo "Copying custom sound"
echo "---------------------"
if [ -d "platforms/android" ]; then
exe mkdir -p platforms/android/res/raw/
exe cp www/sounds/blop.mp3 platforms/android/res/raw/
exe cp www/sounds/blop.caf platforms/ios/zmNinja/Resources
else
echo "Directory platforms/android does not exist, skipping..."
fi
#echo "Copying plist hack for iOS for non SSL connections"
#echo "--------------------------------------------------"
#if [ -d "platforms/ios/zmNinja" ]; then
# exe cp www/external/zmNinja-Info.plist.IOS9nonSSLPatch platforms/ios/zmNinja/zmNinja-Info.plist
#else
Duovili
September 5, 2016, 12:43pm
5
yeah I cant get it to work on ios at all. Does yours work on IOS?
yup. I thought you said you had the same problem I had (which was works on iOS not android)
The code I pointed you to also has blocks for ios.