cordova-plugin-media
cordova-plugin-media copied to clipboard
iOS - Playback failure from device filesystem
I'm having issues playing audio files from a local filesystem on iOS. Please see below for relevant debugging info...
XCODE Output :
2018-09-12 09:16:22.875388+0100 DK EFE[11346:64268] Will attempt to use file resource 'file:///Users/myname/Library/Developer/CoreSimulator/Devices/F7857F73-B645-42C2-8F2C-541E635F9163/data/Containers/Data/Application/D18F7ECE-1809-450B-A644-52E98CD49409/Library/NoCloud/audio/b1/c/3/b1_c_3_2_uk.mp3'
2018-09-12 09:16:22.875580+0100 DK EFE[11346:64268] Unknown resource 'file:///Users/myname/Library/Developer/CoreSimulator/Devices/F7857F73-B645-42C2-8F2C-541E635F9163/data/Containers/Data/Application/D18F7ECE-1809-450B-A644-52E98CD49409/Library/NoCloud/audio/b1/c/3/b1_c_3_2_uk.mp3'
JS Console Output :
{
code: 1,
message: "Cannot use audio file from resource 'file:///Users...'
}
Playback is successful when streaming via Cloudfront CDN but fails when attempting to load locally. The same application is running without any issues on Android.
The debugging output above is fro xcode but experiencing the same issues running application via TestFlight.
Any ideas?
Can you open the URL you are trying to load with the plugin when just creating a simple link and clicking on it?
Thanks for the quick response. Yes i am able to open the file using a link in the application, also via the browser on my local machine (attached screenshots for clarity)
Here is what I try and it works in version 5.0.2:
var path = 'media/sounds/warning.mp3'
// Need to unescape if path have '%20' component
var filePath =
decodeURI(cordova.file.applicationDirectory) + 'www/' + path;
// iOS need to remove file://
if (device.platform.toLowerCase() == 'ios') {
filePath = filePath.replace('file://', '');
}
var audio = new Media(filePath, null,
function(e) {
console.log(JSON.stringify(e));
}, function(status) {
});
audio.setVolume('1.0');
audio.play()
removing file://
works like a charm.
Sadly this is not documented anywhere except in this report.
@zeal-hexsave Duude, you saved my life with this comment 'Need to unescape if path have '%20' component'. I've been beating my head on the problem of sounds not playing at least for a couple of days. Thank you so much.