AVPlayer SeekToTime无法正常工作.每次都从头开始 [英] AVPlayer SeekToTime not working. Starting from beginning everytime

查看:240
本文介绍了AVPlayer SeekToTime无法正常工作.每次都从头开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用UISliderAVPlayer清理方法时遇到了麻烦.每次调用该方法时,播放器将从0重新启动.我尝试调试,并且似乎滑块值正确,但是当我跳过"时,将其设置为0,因此播放器重新启动.这是我尝试过的:

I'm having trouble with UISlider and AVPlayer scrubbing method. Every time the method is invoked the player restarts from 0. I tried debugging and seems that the slider value is right but when I Step Over, it's set 0, thus the player restarts. This is what I've tried:

    var desiredTime = CMTimeMake(Int64(self.progressSlider.value), 1)

    AudioManager.sharedInstance.audioPlayer.seekToTime(desiredTime)

我也尝试过研究类似的问题,发现当我尝试他们的解决方案时,情况是一样的.

I've also tried looking at similar questions and found that it was the same when I tried their solutions.

感谢您的帮助.

推荐答案

正如我在评论中指出的那样,您需要将滑块的最小值设置为0,将其最大值设置为要播放资产的持续时间.

As I indicated in my comment, you need to set the sliders minimum value to 0 and its maximum value to the duration of the asset being played.

要使滑块随着播放器的移动而移动,请向播放器添加一个定期观察者.例如:

To make the slider move as the player plays, add a periodic observer to the player. For example:

CMTime interval = CMTimeMakeWithSeconds(.25,1000); [_player addPeriodicTimeObserverForInterval:interval queue:NULL usingBlock:
    (CMTime time)){ NSTimeInterval t = CMTimeGetSeconds(time);
         mySlider.value = t; }];

(您可能需要一个对self的弱引用才能访问mySlider.) 块的时间参数是玩家的当前时间.

(You may need a weak reference to self to access mySlider.) The time parameter to the block is the player's current time.

用户滑动时,使用seekToTime设置玩家位置.

When the user slides, use seekToTime to set the players position.

一个警告:尽管可以起作用,但是滑块的增量将显示为略微跳动的拇指.我还没有找到使滑块连续移动的简单方法-可能值得一个问题.

One caveat: although this works, the increments of the slider will show as little jumps of the thumb. I have not figured out a simple way to make the slider move continuously - probably worth a question of its own.

这篇关于AVPlayer SeekToTime无法正常工作.每次都从头开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆