2017-08-21 8 views
0

私は以前の録音の一部をトリミングして1つの新しい録音に連結できる録音アプリケーションを作成しています。CreationDateリソース値を変更するには

私の問題は、1時間トラックを録音し、そのトラックの最初の2分間をトリミングしたいとします。この2分間をエクスポートすると、このトラックの作成日は「今すぐ」になり、実際にこの2分間の日付に一致する必要があります。

基本的にトラックのURLリソース値を変更しようとしていますが、作成日のみを変更したいとします。

これを行う方法はありますか?新しいリソース値キーを追加する方法はありますか?またはURLに必要な日付を添付する方法は?

func trimStatringPoint(_ from: Date, startOffSet: TimeInterval, duration: TimeInterval, fileName: String, file: URL, completion: fileExportaionBlock?) { 

    if let asset = AVURLAsset(url: file) as AVAsset? { 
     var trimmedFileUrl = documentsDirectory().appendingPathComponent(fileName) 
     let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetAppleM4A) 
     exporter?.outputFileType = AVFileTypeAppleM4A 
     exporter?.outputURL = trimmedFileUrl 
     let start = CMTimeMake(Int64(startOffSet), 1) 
     let end = CMTimeMake(Int64(startOffSet + duration), 1) 
     exporter?.timeRange = CMTimeRangeFromTimeToTime(start, end) 

     exporter?.exportAsynchronously { handler in 

      if exporter?.status != AVAssetExportSessionStatus.completed { 
       print("Error while exporting \(exporter?.error?.localizedDescription ?? "unknown")") 
       completion?(nil) 
       return 
      } 
     } 
     //------------------------------------------------------ 
     // this code needs to be replaced 
     do { 
       var resourceValus = URLResourceValues() 
       resourceValus.creationDate = from 
       try trimmedFileUrl.setResourceValues(resourceValus) 
     } catch { 
      deleteFile(atPath: trimmedFileUrl) 
      print("Error while setting date - \(error.localizedDescription)") 
      completion?(nil) 
      return 
     } 
     //------------------------------------------------------ 
     completion?(trimmedFileUrl) 
    } 
+0

問題に関連するコードを含めてください。 –

+0

私は質問にコードを追加しました –

答えて

1

エクスポートした録画のメタデータを整理しようとしましたか? https://developer.apple.com/documentation/avfoundation/avmetadatacommonkeycreationdate

AVMutableMetadataItem *item = [AVMutableMetadataItem metadataItem]; 
metaItem.key = AVMetadataCommonKeyCreationDate; 
metaItem.keySpace = AVMetadataKeySpaceCommon; 
metaItem.value = [NSDate date]; 
NSArray *metadata = @{ metaItem }; 
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:composition presetName:AVAssetExportPresetMediumQuality]; 
    exportSession.metadata = metadata; 
+0

ありがとうございました! –

関連する問題