ios - AVAssetExportSession 不适用于 ios 7
<p><p>带有铃声软件的 ios 7 不工作。 ios 5 和 ios 6 工作正常。
当我使用 ios 7 运行它时,铃声的持续时间与创建源文件的时间相同。需要40秒。但似乎是 300-400 秒。</p>
<pre><code>- (void)Convert{
AVURLAsset *songAsset = ;
AVAssetExportSession *exporter = [
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 = [ stringByAppendingPathExtension:@"m4r"];
if ([ fileExistsAtPath:exportFile])
[ removeItemAtPath:exportFile error:nil];
NSURL *exportURL = ;
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;}
}
}];
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这样做是为了设置时间范围</p>
<pre><code>[songAsset insertTimeRange:CMTimeRangeMake(kCMTimeZero, songAsset.duration)
ofTrack:[ objectAtIndex:0]
atTime:kCMTimeZero
error:nil];
</code></pre></p>
<p style="font-size: 20px;">关于ios - AVAssetExportSession 不适用于 ios 7,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19225914/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19225914/
</a>
</p>
页:
[1]