【问题标题】:How can I convert unsupported audio file's format into one of the supported format of iOS?如何将不受支持的音频文件格式转换为 iOS 支持的格式之一?
【发布时间】:2017-03-20 13:52:19
【问题描述】:

在我的应用程序中,不支持从服务器下载的少数音频文件。我的 Objective-C 代码不支持 mpeg、x-wav 音频格式。如何将它们转换为受支持的 iOS 类型之一?

【问题讨论】:

  • 你能具体说明什么文件格式(x-wav 是 MIME)。你想怎么玩?如果你想在代码中转换它,请查看 FFmpeg 库。
  • 确实,你得更具体一些,因为“MPEG”和“WAV”有很多种风格,最常见的肯定是iOS直接支持的,所以你不要需要做任何转换。请分享您的代码和据称不受支持的文件的链接,以及您在尝试播放它们时遇到的任何错误。
  • 我有一个音频 url 链接,我必须将其下载到本地 filePath 并在我的应用程序中播放。该音频 url 是 ci.thrymr.net:8082/file/get?fileid=58d0ce23030b28166b322b79,它是一个 .mpeg 格式的文件。剩余的格式如 . mp3,.mp4,.m4a,.3gpp 工作正常,但 .mpeg 和 x-wav 音频格式没有在我的 ios Objective-c 应用程序的 AVPlayer 中播放。

标签: ios objective-c audio-converter


【解决方案1】:

您可以将它们导入garage band,然后导出为 IOS 兼容格式,例如 .m4a 或 .mp3

【讨论】:

    【解决方案2】:

    下面的代码可能对你有用。并且改变你想要的输出文件类型

    AVAsset * asset = [AVAsset assetWithURL:inputURL];
    AVAssetExportSession * exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
    exportSession.outputFileType = AVFileTypeMPEG4;
    exportSession.outputURL = outputURL;
    exportSession.metadata = asset.metadata;       
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
    
        if (exportSession.status == AVAssetExportSessionStatusCompleted)
        {
                NSLog(@"AV export succeeded.");
        }
        else if (exportSession.status == AVAssetExportSessionStatusCancelled)
        {
            NSLog(@"AV export cancelled.");
        }
        else
        {
            NSLog(@"AV export failed with error: %@ (%ld)", exportSession.error.localizedDescription, (long)exportSession.error.code);
        }
    }];
    

    参考:-

    https://stackoverflow.com/a/41053633

    注意:- 未测试

    【讨论】:

    猜你喜欢
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    • 2013-06-03
    • 2012-12-14
    相关资源
    最近更新 更多