2017-05-22 1 views
0

나는 내가 두 개의 파일을 결합하여 생성 된 파일을 재생할 때, 나는 그것을 잘 재생 또 다른 다시 만들어 사운드 파일을 재생할 때Swift에서 AVPlayer를 사용할 때 왜이 출력을 얻습니까?

playing file:"file location".m4a -- file:/// 

그러나이 출력을 얻을하고, 신속한에서 AVPlayer를 사용하여 오디오 파일을 재생하는 것을 시도하고있다 이것이 내가 오디오

func play(url:NSURL) { 
do { 
    soundPlayer = AVPlayer(url: url as URL) 
    soundPlayer.volume = 1.0 
    soundPlayer.play() 
} catch let error as NSError { 
    print(error.localizedDescription) 
} catch { 
    print("failed") 
} 

} 

을 재생하고 이것이 내가 두 개의 오디오 파일을 연결하기 위해 사용하고 무엇을 어떻게 그것을

재생 후 /// 출력에 : 파일 - 나는 얻지 않는다

,
func makeSounds(sounds: [NSURL], preName: String){ 
    let composition = AVMutableComposition() 
    print(sounds) 

    for sound in sounds { 
    let compositionAudioTrack:AVMutableCompositionTrack = composition.addMutableTrack(withMediaType: AVMediaTypeAudio, preferredTrackID: CMPersistentTrackID()) 
    let avAsset = AVURLAsset(url: sound as URL) 
    let track = avAsset.tracks(withMediaType: AVMediaTypeAudio)[0] 
    let timeRange = CMTimeRange(start: CMTimeMake(0, 600), duration: track.timeRange.duration) 
    try! compositionAudioTrack.insertTimeRange(timeRange, of: track, at: composition.duration) 

    } 


    let documentDirectoryURL = NSURL(fileURLWithPath: Urls.user) 
    var fileDestinationUrl = documentDirectoryURL.appendingPathComponent("\(SoundData.Name)\(preName).m4a") 


    let assetExport = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A) 
    assetExport?.outputFileType = AVFileTypeAppleM4A 
    assetExport?.outputURL = fileDestinationUrl 


    assetExport?.exportAsynchronously(completionHandler: 
     { 
      switch assetExport!.status 
      { 
      case AVAssetExportSessionStatus.failed: 
       print("failed \(assetExport?.error)") 
      case AVAssetExportSessionStatus.cancelled: 
       print("cancelled \(assetExport?.error)") 
      case AVAssetExportSessionStatus.unknown: 
       print("unknown\(assetExport?.error)") 
      case AVAssetExportSessionStatus.waiting: 
       print("waiting\(assetExport?.error)") 
      case AVAssetExportSessionStatus.exporting: 
       print("exporting\(assetExport?.error)") 
      default: 
       soundsToPlay.soundLocation = String(describing: fileDestinationUrl!) 
       print("Audio Concatenation Complete") 
      } 
    }) 



} 

오디오 파일 위치가 내가 그것을 수출하는 설정하고 URL에 올바른 나타나지만 사운드 파일을 재생하지 않습니다, 난 그냥 '

답변

0

AVAssetExportSession가있는 경로 문자열을 필요로하는 오류 'file : ///'이 포함 된 URL.relativeString을 통해 일반적으로 얻은 '파일'형식

관련 문제