电影播放器不会在表格单元格中停止
Posted
技术标签:
【中文标题】电影播放器不会在表格单元格中停止【英文标题】:movie player not stop in table cell 【发布时间】:2014-02-20 07:30:37 【问题描述】:在我的项目中,当单元格可见时,在自定义单元格上显示视频播放。自动
- (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];
所以当我转到另一个视图或标签时如何停止视频
谢谢
【问题讨论】:
【参考方案1】:只需在您需要的UIViewController
中创建一个电影播放器实例,并确保在导航到另一个 VC 或选项卡时破坏该实例。
【讨论】:
但在自定义单元格中查看视频,以便我在自定义单元格中完成所有类型的编程,如果单元格不可见,则在单元格可见时调用,然后我释放所有对象并停止视频。 好吧,尝试使用类的委托方法,而不是您自己的方法,以便在导航到/从它们时以更好的方式处理它们。我认为viewDidLoad
方法会对您有所帮助,具体取决于您想要播放视频的时间。阅读有关viewDidLoad
、viewWillAppear
、viewDidAppear
等的文档。以上是关于电影播放器不会在表格单元格中停止的主要内容,如果未能解决你的问题,请参考以下文章