【问题标题】:AVAssetExportSession not working with ios 7AVAssetExportSession 不适用于 ios 7
【发布时间】:2013-10-07 13:15:41
【问题描述】:

带有铃声软件的 ios 7 不工作。 ios 5 和 ios 6 工作正常。 当我使用 ios 7 运行它时,铃声的持续时间与创建源文件的时间相同。需要40秒。但似乎是 300-400 秒。

- (void)Convert{

    AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:self.audioplayer.url options:nil];

    AVAssetExportSession *exporter = [[AVAssetExportSession alloc]
                                     initWithAsset: songAsset
                                     presetName: AVAssetExportPresetAppleM4A];

    //exporter.outputFileType = @"com.apple.m4a-audio";

    exporter.outputFileType = AVFileTypeAppleM4A;

    CMTime start = CMTimeMakeWithSeconds(self.audioplayer.currentTime, 1);
   CMTime duration = CMTimeMakeWithSeconds(40, 1);
   CMTimeRange range = CMTimeRangeMake(start, duration);
   exporter.timeRange = range;

    NSString *exportFile = [[self kDoc_dosya:self.name] stringByAppendingPathExtension:@"m4r"];


    if ([[NSFileManager defaultManager] fileExistsAtPath:exportFile])
       [[NSFileManager defaultManager] removeItemAtPath:exportFile error:nil];


    NSURL *exportURL = [NSURL fileURLWithPath:exportFile];
   exporter.outputURL = exportURL;

    [exporter exportAsynchronouslyWithCompletionHandler:^{

        int exportStatus = exporter.status;
       switch (exportStatus) {

            case AVAssetExportSessionStatusFailed: {

                NSError *exportError = exporter.error;
               NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);
               break;
           }
           case AVAssetExportSessionStatusCompleted: {
               NSLog (@"AVAssetExportSessionStatusCompleted--");
               break;
           }
            case AVAssetExportSessionStatusUnknown: { NSLog (@"AVAssetExportSessionStatusUnknown"); break;}
           case AVAssetExportSessionStatusExporting: { NSLog (@"AVAssetExportSessionStatusExporting"); break;}
           case AVAssetExportSessionStatusCancelled: { NSLog (@"AVAssetExportSessionStatusCancelled"); break;}
           case AVAssetExportSessionStatusWaiting: { NSLog (@"AVAssetExportSessionStatusWaiting"); break;}
               default: { NSLog (@"didn't get export status"); break;}
           }

        }];
}

【问题讨论】:

    标签: ios objective-c ios7 ringtone avassetexportsession


    【解决方案1】:

    这样做是为了设置时间范围

    [songAsset insertTimeRange:CMTimeRangeMake(kCMTimeZero, songAsset.duration)
                         ofTrack:[[songAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                          atTime:kCMTimeZero
                           error:nil];
    

    【讨论】:

    • 当我使用此代码时出现错误。 'AVURLAsset' 没有可见的@interface 声明选择器'insertTimeRange:ofTrack:atTime:error:'
    • 好的,工作正常。 AVMutableComposition *composition = [AVMutableComposition 组成]; AVMutableCompositionTrack *track = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; [track insertTimeRange:CMTimeRangeMake(kCMTimeZero, songAsset.duration) ofTrack:[[songAsset trackingWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
    猜你喜欢
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    相关资源
    最近更新 更多