我已经创建了一个AVMutableComposition,它由一堆在特定时间开始的音轨组成。在那里,按照苹果的建议,我把它变成了AVComposition,然后再用AVPlayer播放。
播放这个AVPlayer项目可以很好地工作,但如果我暂停它,然后继续,合成中的所有曲目似乎都相对于彼此后退了大约0.2秒(即,它们堆积在一起)。点击暂停和继续几次复合的效果和重叠更显着(基本上,如果我点击它足够,我将结束所有8首曲目同时播放)。
if (self.player.rate > 0.0) {
//if player is playing, pause
[self.player pause];
} else {
if (self.player) {
[self.player play];
return;
}
*/CODE CREATING COMPOSITION - missed out big chunk of code relating to finding the track and retrieving its position and scale/*
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *sourceAsset = [[AVURLAsset alloc] initWithURL:url options:options];
//calculate times
NSNumber *time = [soundArray1 objectAtIndex:1]; //this is the time scale - e.g. 96 or 120 etc.
double timenow = [time doubleValue];
double insertTime = (240*y);
AVMutableCompositionTrack *track =
[composition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
//insert the audio track from the asset into the track added to the mutable composition
AVAssetTrack *myTrack = [[sourceAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
CMTimeRange myTrackRange = myTrack.timeRange;
NSError *error = nil;
[track insertTimeRange:myTrackRange
ofTrack:myTrack
atTime:CMTimeMake(insertTime, timenow)
error:&error];
[sourceAsset release];
}
}
AVComposition *immutableSnapshotOfMyComposition = [composition copy];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:immutableSnapshotOfMyComposition];
self.player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
NSLog(@"here");
[self.player play];谢谢
发布于 2012-11-14 22:25:50
好吧,这感觉有点老生常谈,但如果有人被卡住了,它肯定是有效的。如果有人有更好的答案,一定要让我知道!
基本上,我只是在点击暂停时保存曲目的player.currentTime,并在点击播放时重新制作曲目,只是从我暂停它的点开始。没有明显的延迟,但如果不浪费额外的处理,我会更高兴。
确保你在点击暂停后正确释放你的播放器项目,否则你会得到一个巨大的AVPlayers堆栈!
发布于 2013-10-23 10:04:22
我有一个解决方案,它不那么老套,但仍然很老套。
解决方案来自于我注意到,如果你在播放器上寻找,暂停引入的音频和视频之间的延迟消失了。
因此:只需在暂停前保存player.currentTime,并在再次播放前保存player seekToTime。它在iOS 6上运行得很好,还没有在其他版本上进行测试。
https://stackoverflow.com/questions/13378884
复制相似问题