cordova-plugin-media icon indicating copy to clipboard operation
cordova-plugin-media copied to clipboard

iOS - Playback failure from device filesystem

Open si-harps opened this issue 6 years ago • 5 comments

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?

si-harps avatar Sep 12 '18 09:09 si-harps

Can you open the URL you are trying to load with the plugin when just creating a simple link and clicking on it?

janpio avatar Sep 12 '18 09:09 janpio

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)

screen shot 2018-09-12 at 11 07 41

screen shot 2018-09-12 at 11 07 54

screen-shot-2018-09-12-at-10 59 42

si-harps avatar Sep 12 '18 10:09 si-harps

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()

zeallin avatar Oct 22 '18 11:10 zeallin

removing file:// works like a charm. Sadly this is not documented anywhere except in this report.

nexorianus avatar Apr 30 '19 13:04 nexorianus

@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.

sefrem avatar Feb 02 '21 20:02 sefrem