0
在我的項目中顯示視頻在自定義單元格時,單元格可見視頻播放。自動電影播放器不停留在表單元格
- (void)checkVisibilityOfCell:(CustomCell *)cell inScrollView:(UIScrollView *)aScrollView {
CGRect cellRect = [aScrollView convertRect:cell.frame toView:aScrollView.superview];
if (CGRectContainsRect(aScrollView.frame, cellRect)){
videoPlayingCell = (CustomCell *)cell;
[cell notifyCompletelyVisible];
}else{
[cell notifyNotCompletelyVisible];
}
}
在「notifyCompletelyVisible」方法調用
時完全可見細胞和自定義單元格視頻播放自動多數民衆贊成好的工作,但是當我嘗試去其他視圖或標籤在視頻連續播放我也當消失表視圖停止視頻但打
-(void)notifyCompletelyVisible
{
NSURL *aUrl = [NSURL URLWithString:[dictObj valueForKey:@"videourl"]];
if([self isAlreadySeenVideo:[dictObj valueForKey:@"videourl"]])
{
NSURL *docUrl = [NSURL fileURLWithPath:[self getVideofromDoc:[dictObj valueForKey:@"videourl"]]];
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:docUrl];
} else {
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:aUrl];
}
asyvideoImage.hidden = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieDidExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleNone;
_moviePlayer.shouldAutoplay = YES;
_moviePlayer.view.frame = asyvideoImage.frame;
_moviePlayer.scalingMode=MPMovieScalingModeFill;
[self.contentView insertSubview:_moviePlayer.view belowSubview:tvImageView];
[_moviePlayer prepareToPlay];
[_moviePlayer setFullscreen:NO animated:NO];
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(pauseVideo:)];
[self addGestureRecognizer:singleFingerTap];
}
和我notifyNotCompletelyVisible方法是
-(void)notifyNotCompletelyVisible;
{
[_moviePlayer stop];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieDidExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer];
}
所以如何停止視頻時我去到另一個視圖或標籤
感謝
但在自定義單元格中的視頻視圖,以便我在自定義單元格中完成的所有類型的編程,並在單元格可見時調用,如果單元格不可見,則我釋放所有該對象以及停止視頻。 –
那麼,嘗試使用類的委託方法,而不是自己的方法,以便在導航到/從它們導航期間以更好的方式處理它們。我認爲'viewDidLoad'方法將對您有所幫助,具體取決於您何時播放視頻。閱讀關於'viewDidLoad','viewWillAppear','viewDidAppear'等的文檔 – Neeku