Ios MPMoviePlayer似乎指向同一个实例
我正在Ios MPMoviePlayer似乎指向同一个实例,ios,objective-c,uitableview,mpmovieplayercontroller,mpmovieplayer,Ios,Objective C,Uitableview,Mpmovieplayercontroller,Mpmovieplayer,我正在UITableView单元格中创建一些玩家,作为一个有趣的项目 例: 上述内容在表视图单元格子类中创建,然后添加到contentView。没有任何花哨和自定义覆盖,每一个默认 他们表现得很好。出于测试目的,我为每个玩家使用相同的url 它起作用,但问题发生了,因为我认为每个玩家都是同一个对象 我的意思是,当我开始在一个单元格中播放一个时,我可以看到另一个(随机)也在播放。如果我在一个播放器中启动然后停止,我可以通过单击另一个单元格中的另一个播放器来恢复播放 我不知道问题从何而来,因为我正在
UITableView
单元格中创建一些玩家,作为一个有趣的项目
例:
上述内容在表视图单元格子类中创建,然后添加到contentView
。没有任何花哨和自定义覆盖,每一个默认
他们表现得很好。出于测试目的,我为每个玩家使用相同的url
它起作用,但问题发生了,因为我认为每个玩家都是同一个对象
我的意思是,当我开始在一个单元格中播放一个时,我可以看到另一个(随机)也在播放。如果我在一个播放器中启动然后停止,我可以通过单击另一个单元格中的另一个播放器来恢复播放
我不知道问题从何而来,因为我正在初始化每个表视图单元格子类中的播放器(即,每个单元格都应该有自己的播放器)
因此,除此之外,我不得不假设——如果每个玩家打开相同的url,API是否会应用一些“魔法”,即它不会分配更多的玩家,并且每个玩家都指向同一个(实例),即使我们实际上是alloc并初始化多个玩家
这真让我受不了
Cell子类(我只测试播放器,因此没有其他自定义标签、视图或排序。只有播放器): 以及:
- (void)finished:(NSNotification*)notification
{
NSLog(@"finished");
//This gets called multiple times endlessly even with 1 cell
//and without scrolling. But when added on UIView the notification
//will only be called once on the UIView class.
}
何时何地将它们添加到内容视图?用什么方法?如果不是
init
,什么调用该方法以及何时调用?是屏幕上的两个单元格同时播放在一起,还是必须滚动?可能是“随机单元格”,您可以在其中恢复相同的视频。试着在prepareForReuse
@vhristoskov中清除播放器的状态,这是我的想法,但是一个单元格和它被重用的单元格永远不能同时出现在屏幕上。可能包括单元格子类中的相关代码?
//Here in initWithStyle, after alloc and initializing the player
//.....
self.player.controlStyle = MPMovieControlStyleEmbedded;
[self.contentView addSubview:self.player.view];
//player is declared as a property with `strong and nonatomic`
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(finished:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
[self.player prepareToPlay];
//End initWithStyle
- (void)finished:(NSNotification*)notification
{
NSLog(@"finished");
//This gets called multiple times endlessly even with 1 cell
//and without scrolling. But when added on UIView the notification
//will only be called once on the UIView class.
}