mov 파일을 스트리밍하는 앱이 있습니다. 내 응용 프로그램의 기능 중 하나는 이러한 스트리밍 된 파일을 통해 오디오를 녹음하는 것입니다. 이를 위해 백그라운드에서 스트리밍 된 파일을 다운로드 한 다음 오디오를 캡처하여 사용자 오디오를 캡처합니다. 일단 사용자가 완료되면 녹음 된 오디오를 가져 와서 이전에 백그라운드에서 다운로드 한 mov 파일과 병합합니다.헤드폰 연결시 이상한 AVMutableComposition 동작
헤드폰을 꽂은 경우를 제외하면이 모든 기능이 잘 작동합니다. 경험은 동일하지만 녹음을 재생할 때 오디오 만 캡처되었습니다. mov 파일은 이유를 모르는 최종 자산으로 만들지 않습니다. 여기
내가 녹음을 생산하고 있습니다 방법은 다음과 유사
let video = AVAsset(URL: currentCacheUrl)
let audioRecording = AVAsset(URL: currentRecordingUrl)
// 1 - Create AVMutableComposition object. This object will hold your AVMutableCompositionTrack instances.
let mixComposition = AVMutableComposition()
// 2 - Video track
let videoTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid)
do {
try videoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, audioRecording.duration),
ofTrack: video.tracksWithMediaType(AVMediaTypeVideo)[0],
atTime: kCMTimeZero)
} catch _ {
print("Failed to load video track")
}
// 3 - Audio track
let audioTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeAudio, preferredTrackID: 0)
do {
try audioTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, audioRecording.duration),
ofTrack: audioRecording.tracksWithMediaType(AVMediaTypeAudio)[0],
atTime: kCMTimeZero)
} catch _ {
print("Failed to load audio track")
}
// 4 - Get path
let recordingsPath = MisueroKaraokeLatinoHelper.Variables.getRecordingsDirectory
let currentDate = NSDate()
let date = formatDate(currentDate)
let savePath = recordingsPath.URLByAppendingPathComponent("\(date).mov")
// 5 - Create Exporter
guard let exporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality) else { return }
exporter.outputURL = savePath
exporter.outputFileType = AVFileTypeQuickTimeMovie
exporter.shouldOptimizeForNetworkUse = true
// 6 - Perform the Export
exporter.exportAsynchronouslyWithCompletionHandler() {
dispatch_async(dispatch_get_main_queue()) { _ in
print("save and merge complete")
let recording = Recording(title: self.currentRecordSong.title, artist: self.currentRecordSong.artist, genre: self.currentRecordSong.genre, timestamp: currentDate, fileUrl: savePath)
MisueroKaraokeLatinoHelper.Variables.Recordings.append(recording)
MisueroKaraokeLatinoHelper.Variables.Recordings.sortInPlace({$0.timestamp.compare($1.timestamp) == NSComparisonResult.OrderedDescending})
let recordingsData = NSKeyedArchiver.archivedDataWithRootObject(MisueroKaraokeLatinoHelper.Variables.Recordings)
NSUserDefaults.standardUserDefaults().setObject(recordingsData, forKey: "Recordings")
}
}
뭔가는 iOS 장비가이 때 블루투스 장치로 설정 오디오 출력의 발생합니다. 최종 녹음은 사용자가 녹음 한 오디오 및 비디오를 mov 파일에 캡처하지만 mov 파일의 오디오는 캡처하지 않습니다. 뭐라 구요?