Airpods вызывают сбой экспорта AVAssetExportSession - PullRequest
0 голосов
/ 23 января 2019

Запись и экспорт без Airpods работают нормально, но не удалось при использовании Airpods.

Я правильно установил режим AVAudioSession.

private func defaultRecordSetting() {
    do {
        try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.mixWithOthers, .duckOthers, .allowBluetooth, .defaultToSpeaker, .interruptSpokenAudioAndMixWithOthers, .allowBluetoothA2DP, .allowAirPlay])
        try AVAudioSession.sharedInstance().setActive(true)
    } catch {
        //Didn't work
    }
}

private func mergeClips(clipsCount: Int) {
    let assets = clipFiles.map{ AVURLAsset(url: $0) }
    mergeAssets(arrayVideos: assets) { session in
        switch session.status {
        case .completed:
                print("Good!")
        default:
            if let error = session.error {
                print(error)
            }
        }
    }
}

func mergeAssets(arrayVideos:[AVAsset], completion: @escaping (_ exporter: AVAssetExportSession) -> ()) {

    let mainComposition = AVMutableComposition()
    let compositionVideoTrack = mainComposition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid)

    let soundtrackTrack = mainComposition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: kCMPersistentTrackID_Invalid)

    var insertTime = CMTime.zero

    for videoAsset in arrayVideos {
        for track in videoAsset.tracks(withMediaType: AVMediaType.video) {
            try! compositionVideoTrack?.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: videoAsset.duration), of: track, at: insertTime)
        }
        for track in videoAsset.tracks(withMediaType: AVMediaType.audio) {
            try! soundtrackTrack?.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: videoAsset.duration), of: track, at: insertTime)
        }

        insertTime = CMTimeAdd(insertTime, videoAsset.duration)
    }

    let exporter = AVAssetExportSession(asset: mainComposition, presetName: AVAssetExportPresetHighestQuality)

    exporter?.outputURL = FILE_URL
    exporter?.outputFileType = AVFileType.mp4
    exporter?.shouldOptimizeForNetworkUse = true

    exporter?.exportAsynchronously {
        DispatchQueue.main.async {
            completion(exporter!)
        }
    }
}

AVAssetExportSession exportAsynchronically ошибка ошибки userInfo содержит три ошибки:

  1. NSLocalizedFailureReason: этот формат мультимедиа не поддерживается.
  2. NSLocalizedDescription: Невозможно открыть
  3. NSUnderlyingError: Ошибка домена = NSOSStatusErrorDomain Code = -16976 "(null)"

Как правильно обращаться с Airpods? Спасибо!

...