Cordova 媒体插件未在 iOS 上播放本地文件

Cordova Media Plugin not playing local file on iOS

我在使用媒体插件播放从本地存储下载的音频文件时遇到问题。

我正在使用 FileTransfer 插件将文件下载到 LocalFileSystem.TEMPORARY 目录。

播放前,我使用以下代码检查音频文件是否存在:

window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) {
        var rootdir = fileSystem.root;
        var dir_path = rootdir.toURL();
        
        if (success_callback) {
            if (file_name && file_name !== "") {
                success_callback(dir_path + file_name);
            } else {
                success_callback(dir_path);
            }
        }
    }, function () {
        if (error_callback) {
            error_callback("Error in FileSystem request");
        }
    });

上述方法验证文件是否存在于临时存储目录中。

但是当我播放文件时,我在 iOS 上出现以下日志 的错误:

> File Transfer Finished with response code 200
> Audio downloaded successfully. Location: file:///var/mobile/Containers/Data/Application/0B5359AD-0F9E-4FB1-BEB3-71713973A8A2/tmp/user_timestamp.wav
> Play local file from: file:///var/mobile/Containers/Data/Application/0B5359AD-0F9E-4FB1-BEB3-71713973A8A2/tmp/user_timestamp.wav
> Will attempt to use file resource from LocalFileSystem.TEMPORARY directory
> Failed to initialize AVAudioPlayer: The operation couldn’t be completed. (OSStatus error 2003334207.)
> playAudio() Error: {"message":"","code":4}

我试过为 Media 对象提供完整路径和文件名,但这两种方法都不起作用。任何帮助将不胜感激。

我发现了问题所在。问题是 iOS 没有播放在 Android 上录制的文件。它可以毫无问题地播放 iOS 个录制的文件。

以下link帮助我在Android和[=22=中设置媒体插件文件AudioPlayer.java ] 在 iOS 中设置类似,现在每个平台的音频都可以在其他平台上播放。

audio format for iOS and Android