如何检测,当iPhone MPMoviePlayer控件出现/消失?
-
20-09-2019 - |
题
我试图自定义按钮添加到左侧和标准倒带/播放/向前控制权在的MPMoviePlayerController视图(OS 2.x和向上)。我已经想通了如何将它们添加到播放器窗口,但他们始终可见。有一种方法来检测时的标准控件出现和消失?
解决方案
好,知道了,使这样的:
BOOL controlsVisible = NO;
for(id views in [[_moviePlayer view] subviews]){
for(id subViews in [views subviews]){
for (id controlView in [subViews subviews]){
controlsVisible = ([controlView alpha] <= 0.0) ? (NO) : (YES);
}
}
}
NSLog(@"player controls are visible: %d", controlsVisible);
其中的 _movePlayer 是您的播放器的实例。 在最深的循环中,在 MPFullScreenVideoOverlay 查看实例将具有阿尔法== 0.0如果控件都被隐藏,或者如果显示的控件阿尔法1.0。 您可以添加一个观察者,并根据需要火的东西。我知道是不是优雅,但它为我工作,因为对此任务苹果也没有记录任何东西。
干杯...
其他提示
cybercow的答案是正确的只需要添加少量的修改,使答案更准确。
BOOL controlsVisible = NO;
for(id views in [[self.moviePlayerViewController view] subviews])
{
for(id subViews in [views subviews])
{
for (id controlView in [subViews subviews])
{
if ([controlView isKindOfClass:[UIView class]] && ((UIView*)controlView).tag == 1004)
{
controlsVisible = ([controlView alpha] <= 0.0) ? (NO) : (YES)
}
}
}
}
我改变了最内层循环。实际上1004是MPMoviePlayer的标签进行控制,使得它会更精确地工作。
看到movieControlMode属性。可以设置MPMovieControlMode
MPMovieControlMode选项用于显示电影播放控件。
typedef enum {
MPMovieControlModeDefault,
MPMovieControlModeVolumeOnly,
MPMovieControlModeHidden
}
MPMovieControlMode;
您还可以检查出MPMoviePlayerScalingModeDidChangeNotification
<强>预iOS3.2 强>结果 检测 “disapierance” 是容易的:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
检测appierance是有点困难(也许有更好的方法):
...
[moviePlayerController play];
mainTimer = [NSTimer scheduledTimerWithTimeInterval:1/100 target:self selector:@selector(tick) userInfo:nil repeats:YES];
- (void)tick {
if( [[[UIApplication sharedApplication] windows] count] < 2 ) return;
moviePlayerWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
if( moviePlayerWindow ){
[mainTimer invalidate], mainTimer=nil;
// here you have moviePlayerWindow
}
}
不隶属于 StackOverflow