AVAssetExportSession с outputFileType m4a не работает iOS13 - PullRequest
1 голос
/ 01 октября 2019

Я подозреваю, что Xcode 11 с iOS13 не работает Xcode 10.2.1 с iOS12.2 работает нормально

Я пытаюсь объединить два аудиофайла в один аудиофайл.

Сильфонный код работает нормально Xcode 10.2.1 с iOS 12.2, но теперь работает xcode 11 с iOS13

   @objc func applyMergeAudio(){

        playmerge(audio1: Bundle.main.url(forResource: "audio0", withExtension: "mp3")!,audio2: Bundle.main.url(forResource: "Asteroid_Sound", withExtension: "mp3")!)
    }

    func playmerge(audio1: URL, audio2:  URL)
    {
        let composition = AVMutableComposition()
        let compositionAudioTrack1:AVMutableCompositionTrack = composition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: CMPersistentTrackID())!
        let compositionAudioTrack2:AVMutableCompositionTrack = composition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: CMPersistentTrackID())!

        let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        let fileDestinationUrl = documentDirectoryURL.appendingPathComponent("resultmerge.m4a")

        let filemanager = FileManager.default
        if (!filemanager.fileExists(atPath: fileDestinationUrl.path))
        {
            do
            {
                try filemanager.removeItem(at: fileDestinationUrl)
            }
            catch let error as NSError
            {
                NSLog("Error: \(error)")
            }
        }

        let avAsset1 = AVURLAsset(url: audio1, options: nil)
        let avAsset2 = AVURLAsset(url: audio2, options: nil)

        var tracks1 = avAsset1.tracks(withMediaType: AVMediaType.audio)
        var tracks2 = avAsset2.tracks(withMediaType: AVMediaType.audio)

        let assetTrack1:AVAssetTrack = tracks1[0]
        let assetTrack2:AVAssetTrack = tracks2[0]

        let duration1: CMTime = assetTrack1.timeRange.duration
        let duration2: CMTime = assetTrack2.timeRange.duration

        let timeRange1 = CMTimeRangeMake(start: CMTime.zero, duration: duration1)
        let timeRange2 = CMTimeRangeMake(start: CMTime.zero, duration: duration2)
        do
        {
            try compositionAudioTrack1.insertTimeRange(timeRange1, of: assetTrack1, at: CMTime.zero)
            try compositionAudioTrack2.insertTimeRange(timeRange2, of: assetTrack2, at: CMTime.zero)
        }
        catch
        {
            print(error)
        }

        //below line force unwarp Version xcode 10.2.1 working fine with iOS12.2. but xcode 11 with iOS13 got crush . .
        let assetExport = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A)
        assetExport?.outputFileType = AVFileType.m4a
        assetExport?.outputURL = fileDestinationUrl
        assetExport?.exportAsynchronously(completionHandler:
            {
                //xcode 11 with iOS13 not fire this block but xcode 10.2.1 with iOS12.2 working fine.
                print(fileDestinationUrl)
        })
    }

, так что вы бы сказали мне альтернативное решение или я что-то пропустил ?.

1 Ответ

1 голос
/ 01 октября 2019

Не так много ответов, но было бы трудно передать все это как комментарий.

Для Apple , в AVAssetExportSession есть функция, которую вы можете вызвать namedallExportPresets(), который выведет все доступные предустановки.

Вы также можете позвонить exportPresets(compatibleWith:) со своим AVAsset, чтобы найти совместимые с этим конкретным активом.

Когда я звоню allExportPresets() с IOS 12 , я получаю следующий результат:

[ "AVAssetExportPreset1920x1080", "AVAssetExportPresetLowQuality", "AVAssetExportPresetAppleM4A", "AVAssetExportPresetHEVCHighestQuality", "AVAssetExportPreset640x480", "AVAssetExportPreset3840x2160", «AVAssetExportPresetHEVC3840x2160», «AVAssetExportPresetHighestQuality», «AVAssetExportPreset1280x720», «AVAssetExportPresetMediumQuality», «AVAssetExportPreset960x540», «AVAssetExportPreset960x540», «AVAssetExportPreset960x540», «* * * * * * * * * *»получить:

[]

Когда я проверяю страницы поддержки дляОднако в различных предустановках я не могу найти какую-либо документацию, подтверждающую, что они устарели и т. д.

Я могу попытаться проверить позже, чтобы посмотреть, смогу ли я добавить к этому.

Надеюсь, что это возможно вхотя бы дать некоторые указания на данный момент.

...