首页 文章

有没有办法阻止AVPlayer的速率属性被重置?

提问于
浏览
0

我正在使用AVPlayer对象进行视频播放,并具有调整播放器速率的控件 .

除了每按一次停止/暂停按钮时AVplayer对象的速率值似乎重置为1.0,这一切都正常 . 有没有办法防止这种情况发生?

非常感谢 .

4 回答

  • 0

    [AVPlayer play] 相当于 [AVPlayer setRate:1.0]

    [AVPlayer pause] 相当于 [AVPlayer setRate:0.0]

  • 5

    为此,谷歌的利益......

    每次播放器开始播放时,rate属性都会重置为1.0,因此您需要在其他地方保持比率值,并在每次播放时重新应用它 .

  • 0

    MPMediaItem为您提供了一个属性来读取媒体项的每分钟节拍数 .

    像这样的东西 -

    MPMediaItem *item = [[MPMediaItem alloc]init] ;
    .
    .
    .
    int BPM =  [item valueForProperty:MPMediaItemPropertyBeatsPerMinute];
    

    现在计算您要设置媒体项目费率的比率 -

    float rate = newBPM/(float)BPM; // lets say BPM = 100, You want to double the rate of the media then newBPM = 200
    

    现在将此速率设置为AVPlayer对象 -

    [AVPLayer setRate:rate];
    
  • 0

    通过AVPlayer的“播放”方法重置速率是奇怪但真实的 . 我用以下代码作为解决方法来加载新的播放器项目,调整播放速率并让它播放:

    [self.player replaceCurrentItemWithPlayerItem: [AVPlayerItem playerItemWithURL: movieURL]];
    self.player.rate = PLAYER_RATE;
    [self.player seekToTime: kCMTimeZero];
    

相关问题