Cordova video / audio won't play from cdvfile:// urls after update to 3.3.0

后端 未结 3 1638
一向
一向 2020-12-14 12:50

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

3条回答
  •  -上瘾入骨i
    2020-12-14 13:13

    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
    

提交回复
热议问题