首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AVPlayer seekToTime纺纱比萨饼

AVPlayer seekToTime纺纱比萨饼
EN

Stack Overflow用户
提问于 2015-03-10 19:49:23
回答 1查看 217关注 0票数 2

我有一个简单的基于AVPlayer的OS应用程序,可以播放本地媒体。它具有基于-seekToTime:的跳过向前和向后的特性。在一些媒体上,让媒体继续播放(尤其是向前看)有一个恼人的3-7秒的延迟。我试过-寻找时间:公差之前:公差之后:,有可变的公差。不走运。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-10 19:55:49

把以前解决的问题记录在案.我注意到,当播放暂停时,seekToTime:跳过很好。我立即(即几周后)意识到,在寻找之前停止播放,然后重新启动可能是有意义的。到目前为止,问题已经百分之百地解决了,而且非常迅速。对于那些试图进行平滑循环的人来说,可能有些用处(但我不知道如何触发指示循环结束的完成处理程序)。不知道它是否适用于iOS。附件中附有示例代码:

代码语言:javascript
运行
复制
-(void) movePlayheadToASpecificTime
{
    // assumes this is a method for an AVPlayerView subclass, properly wired with IB
    // self.player is a property of AVPlayerView, which points to an AVPlayer

    // save the current rate
    float currentPlayingRate = self.player.rate;

    // may need fancier tweaking if the time scale changes within asset
    int32_t timeScale = self.player.currentItem.asset.duration.timescale;

    // stop playback
    self.player.rate = 0;

    Float64 desiredTimeInSeconds = 4.5; // or whatever

    // convert desired time to CMTime
    CMTime target = CMTimeMakeWithSeconds(desiredTimeInSeconds, timeScale);

    // perform the move
    [self.player seekToTime:target];

    // restore playing rate
    self.player.rate = currentPlayingRate;

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

https://stackoverflow.com/questions/28972819

复制
相关文章

相似问题

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