【问题标题】:how to trim or play a audio from begin time to end time in iOS?如何在 iOS 中从开始时间到结束时间修剪或播放音频?
【发布时间】:2013-08-02 09:46:02
【问题描述】:

这类似于iTunes的修剪功能,传递以下两个参数以获得我想要的修剪音频。

例如。 开始时间:00:23.12

停止时间:01:33.54

如果有帮助,不胜感激!

【问题讨论】:

    标签: ios audio avplayer trim


    【解决方案1】:

    同一主题有多种问题可供选择:

    iOS Audio Trimming

    How to trim audio file in iPhone?

    How to trim audio data?

    How to crop audio in ios

    这是一个示例代码:

    http://code4app.net/ios/Trim-Control/51121a886803fa071d000001

    希望这可以帮助您实现您的功能。

    【讨论】:

    【解决方案2】:

    如果您在 2016 年阅读本文并且正在寻找解决方案。它对我有用(swift 2.3):

    let exporter = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A)
        exporter!.outputURL = soundFile1
        exporter!.outputFileType = AVFileTypeAppleM4A
        let duration = CMTimeGetSeconds(avAsset1.duration)
        print(duration)
        if (duration < 5.0) {
            print("sound is not long enough")
            return
        }
        // e.g. the first 30 seconds
        let startTime = CMTimeMake(0, 1)
        let stopTime = CMTimeMake(30,1)
        let exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime)
        print(exportTimeRange)
        exporter!.timeRange = exportTimeRange
        print(exporter!.timeRange)
    

    【讨论】:

    • 究竟是 5.0 分钟或秒 ??
    • 如果我想修剪音频但时间不到 5 分钟,请回复。
    猜你喜欢
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 2020-02-19
    • 2021-04-29
    • 1970-01-01
    相关资源
    最近更新 更多