forwardPlaybackEndTime不起作用 [英] forwardPlaybackEndTime does not work
问题描述
AVPlayerItem
具有此属性forwardPlaybackEndTime
该值表示在播放结束时播放应结束的时间 播放速率为正(请参阅AVPlayer的rate属性).
The value indicated the time at which playback should end when the playback rate is positive (see AVPlayer’s rate property).
默认值为kCMTimeInvalid,表示没有结束时间 指定用于正向播放.在这种情况下,有效结束 向前播放的时间是该项目的持续时间.
The default value is kCMTimeInvalid, which indicates that no end time for forward playback is specified. In this case, the effective end time for forward playback is the item’s duration.
但是我不知道为什么它不起作用.我尝试在AVPlayerItemStatusReadyToPlay
中设置它,持续时间可用,回调,...但是它没有任何作用,只是播放到最后
But I don't know why it does not work. I tried to set it in AVPlayerItemStatusReadyToPlay
, duration available callback, ... but it does not have any effect, it just plays to the end
我认为forwardPlaybackEndTime
用于限制播放头,对吗?
在我的应用中,我只想从电影的开头到一半播放
I think that forwardPlaybackEndTime
is used to restrict the playhead, right?
In my app, I want to play from the beginning to the half of the movie only
我的代码如下
- (void)playURL:(NSURL *)URL
{
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:URL];
if (self.avPlayer) {
if (self.avPlayer.currentItem && self.avPlayer.currentItem != playerItem) {
[self.avPlayer replaceCurrentItemWithPlayerItem:playerItem];
}
} else {
[self setupAVPlayerWithPlayerItem:playerItem];
}
playerItem.forwardPlaybackEndTime = CMTimeMake(5, 1);
// Play
[self.avPlayer play];
}
如何使forwardPlaybackEndTime
工作?
推荐答案
我认为您必须更新avPlayer's current playerItem
.
所以
playerItem.forwardPlaybackEndTime = CMTimeMake(5, 1);
应为:
self.avPlayer.currentItem.forwardPlaybackEndTime = CMTimeMake(5, 1);
这篇关于forwardPlaybackEndTime不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!