My Cordova app downloads audio files from a server and makes them available to play when the device is offline. This was all working fine until yesterday when I upgraded to
I still don't have an answer for getting a fully qualified path, but I decided to hack the iOS plugin until there is a proper fix from Cordova. (At least I can continue on with dev for the moment.)
The following code was taken from the file-transfer
plugin, and can be added to CDVSound.m to allow the media plugin to play audio files with the new cdvfile://
paths, iOS only. Be warned though, I have never written a line of ObjC before and the code has hardly been tested. It is a temp fix until Cordova patches the current plugin.
#import "CDVSound.h"
#import "CDVFile.h" <-- add
#import
...
#define RECORDING_WAV @"wav"
#define CDVFILE_PREFIX @"cdvfile://" <-- add
extern CDVFile *filePlugin; <-- add
@implementation CDVSound
...
filePath = [resourcePath stringByReplacingOccurrencesOfString:DOCUMENTS_SCHEME_PREFIX withString:[NSString stringWithFormat:@"%@/", docsPath]];
NSLog(@"Will use resource '%@' from the documents folder with path = %@", resourcePath, filePath);
<--- insert this block here --->
} else if ([resourcePath hasPrefix:CDVFILE_PREFIX]) {
CDVFilesystemURL *fsURL = [CDVFilesystemURL fileSystemURLWithString:resourcePath];
if (fsURL && fsURL.fileSystemName != nil) {
// This requires talking to the current CDVFile plugin
NSObject *fs = [filePlugin filesystemForURL:fsURL];
if ([fs respondsToSelector:@selector(filesystemPathForURL:)]) {
filePath = [fs filesystemPathForURL:fsURL];
NSLog(@"Will use resource '%@' from the documents folder with path = %@", resourcePath, filePath);
}
else {
resourceURL = fsURL.url;
}
}
else {
NSLog(@"Unknown resource '%@'", resourcePath);
}
<--- to here --->
} else {
// attempt to find file path in www directory or LocalFileSystem.TEMPORARY directory