我有表單視圖,其中單元格從Parse加載視頻對象。 加載視頻時,playButton會出現在視頻的靜態圖像表示上。播放按鈕是故事板UIButton的出口。當playButton被推動時暫停AVPlayer的其他實例
在我FeedCell.m:
- (IBAction)playButtonTapped:(id)sender {
[self.player play];
if (self.player.rate != 0 && (self.player.error == nil)) {
// player is playing
self.playButton.hidden = YES;
}
self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector: @selector (playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.player currentItem]];
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
self.playButton.hidden = NO;
[self.playerItem seekToTime:kCMTimeZero];
[self.player pause];
}
我想添加到這個按鈕的功能,這樣當爲playButton被竊聽的AVPlayerItem將發揮和AVPlayers的其他所有實例都將被暫停。
我可以通過設置另一個NSNotification來做到這一點嗎?
有沒有一種方法可以影響已經滾動出視野的單元? –
您可以改爲使用'AVQueuePlayer'。這會讓你預先加載資源,然後隨時按下playButton,它會停止正在播放的資產並轉到新的資產 – MikeG