首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >暂停时AVComposition中的磁道丢失时间

暂停时AVComposition中的磁道丢失时间
EN

Stack Overflow用户
提问于 2012-11-14 20:31:35
回答 2查看 636关注 0票数 1

我已经创建了一个AVMutableComposition,它由一堆在特定时间开始的音轨组成。在那里,按照苹果的建议,我把它变成了AVComposition,然后再用AVPlayer播放。

播放这个AVPlayer项目可以很好地工作,但如果我暂停它,然后继续,合成中的所有曲目似乎都相对于彼此后退了大约0.2秒(即,它们堆积在一起)。点击暂停和继续几次复合的效果和重叠更显着(基本上,如果我点击它足够,我将结束所有8首曲目同时播放)。

代码语言:javascript
复制
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];

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-14 22:25:50

好吧,这感觉有点老生常谈,但如果有人被卡住了,它肯定是有效的。如果有人有更好的答案,一定要让我知道!

基本上,我只是在点击暂停时保存曲目的player.currentTime,并在点击播放时重新制作曲目,只是从我暂停它的点开始。没有明显的延迟,但如果不浪费额外的处理,我会更高兴。

确保你在点击暂停后正确释放你的播放器项目,否则你会得到一个巨大的AVPlayers堆栈!

票数 0
EN

Stack Overflow用户

发布于 2013-10-23 10:04:22

我有一个解决方案,它不那么老套,但仍然很老套。

解决方案来自于我注意到,如果你在播放器上寻找,暂停引入的音频和视频之间的延迟消失了。

因此:只需在暂停前保存player.currentTime,并在再次播放前保存player seekToTime。它在iOS 6上运行得很好,还没有在其他版本上进行测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13378884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档