Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何改变创造性资源价值_Ios_Swift_Swift3_Avfoundation_Nsfilemanager - Fatal编程技术网

Ios 如何改变创造性资源价值

Ios 如何改变创造性资源价值,ios,swift,swift3,avfoundation,nsfilemanager,Ios,Swift,Swift3,Avfoundation,Nsfilemanager,我正在编写一个录音应用程序,使用户可以修剪以前录制的部分内容,并将它们连接到一个新的录音中 我的问题是:假设我录制了一个小时长的曲目,我想删减该曲目的前2分钟。当我导出这2分钟时,这首曲目的创建日期将是“现在”,我需要它与这2分钟实际发生的日期相匹配 因此,基本上我试图修改tracks Url资源值,但我只想更改创建日期 有办法做到这一点吗?或者有没有办法添加新的资源值键?还是将所需日期附加到url的方法 func trimStatringPoint(_ from: Date, startOff

我正在编写一个录音应用程序,使用户可以修剪以前录制的部分内容,并将它们连接到一个新的录音中

我的问题是:假设我录制了一个小时长的曲目,我想删减该曲目的前2分钟。当我导出这2分钟时,这首曲目的创建日期将是“现在”,我需要它与这2分钟实际发生的日期相匹配

因此,基本上我试图修改tracks 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)
    }

您是否尝试过将导出的录制的元数据格式化?


请为您的问题添加一些相关代码。我在问题中添加了代码,请看一看
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;