の上に私は、mpmovieplayercontrollerの上にオーバーレイしようとしているは、オーバーレイは、ストリーミングMPMoviePlayerController
イムアップルから「iPhone上のMoviePlayer」、
それは完全にバンドルしているビデオクリップで動作例を経て
しかし、URLから動画をストリーミングするとうまくいかない場合があります。
オーバーレイビューはプレーヤーの背後に隠れるだけです。
オーバーレイビューを前面に表示する方法はありますか?
の上に私は、mpmovieplayercontrollerの上にオーバーレイしようとしているは、オーバーレイは、ストリーミングMPMoviePlayerController
イムアップルから「iPhone上のMoviePlayer」、
それは完全にバンドルしているビデオクリップで動作例を経て
しかし、URLから動画をストリーミングするとうまくいかない場合があります。
オーバーレイビューはプレーヤーの背後に隠れるだけです。
オーバーレイビューを前面に表示する方法はありますか?
MPMoviePlayerControllerは独自のウィンドウを作成し、これをキーウィンドウとして設定します。これはMoviePlayerサンプルアプリケーションからすでにわかっているはずです。
理由はわかりませんが、プレーヤーがストリームを使用すると遅延があります。そのため、後で追加されるようだから、プレーヤーを初期化した直後のキーウィンドウはプレイヤーのウィンドウではない可能性があります。
あなたが「カンニング」と数秒後にプレーヤーのウィンドウを取得するためにタイマーを使用して、あなたのオーバーレイを追加することができます。
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(addMyOverlay:) userInfo:nil repeats:FALSE]
それとも、UIWindowDidBecomeKeyNotificationイベントをリッスンし、同じ操作を行うことができます。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyWindowChanged:) name:UIWindowDidBecomeKeyNotification object:nil];
どちらのオプションも素晴らしいです(これを行うにはもっとクリーンな方法を知りたいですが)。
以前の回答は、タイマーに基づいていました。 & 5秒固定。
ムービープレーヤーが起動すると、新しいウィンドウがアプリケーションに追加されます。
アプリケーションに新しいウィンドウが追加されたかどうかを確認するには、タイマーを使用します。
ウィンドウ(ムービープレーヤーウィンドウ)が追加されたとき。通知を設定します。
-(void)viewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
// Register to receive a notification when the movie scaling mode has changed.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieScalingModeDidChange:)
name:MPMoviePlayerScalingModeDidChangeNotification
object:nil];
videoListController.xmlClassVideoList=t;
// here ttttt is a timer declared in .h file
tttttt=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(startMy) userInfo:nil repeats:YES];
}
-(void)startMy{
NSArray *windows = [[UIApplication sharedApplication] windows];
NSLog(@"%i",[windows count]);
// depends on your application window
// it may be 1/2/3
if ([windows count] > 3) {
// Locate the movie player window
[tttttt invalidate];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyWindowChanged:) name:UIWindowDidBecomeKeyNotification object:nil];
}
}
私は、0.5秒ごとにチェックするのが5秒待つよりも理にかなっていることに同意しますが、最初からUIWindowDidBecomeKeyNotificationを待ち受けてタイマーを忘れるのはなぜですか? –
あなたが「MPMoviePlayerContentPreloadDidFinishNotification」の通知を受信したときあなたはあなたのビューをオーバーレイすることができます。
通知を登録する:通知を受信したとき
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
は、オーバーレイビューを追加します。
// Notification called when the movie finished preloading.
- (void) moviePreloadDidFinish:(NSNotification*)notification
{
NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] > 1)
{
// Locate the movie player window
UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
if ([moviePlayerWindow viewWithTag:0x3939] == nil) {
self.videoOverlayView.tag = 0x3939;
[moviePlayerWindow addSubview:self.videoOverlayView];
}
[moviePlayerWindow bringSubviewToFront:self.videoOverlayView];
}
}
非常にシンプルなソリューション:
appDelegate.window.backgroundColor = [UIColor clearColor];
appDelegate.window.windowLevel = 2;
をこれが上のアプリのUIを維持しますビデオウィンドウの上部。
あなたは男です!あなたは私の問題を解決しました!ありがとうalot – vicky
私は実際には、UIWindowDidBecomeKeyNotificationを使用する代わりに、それは完全に動作します。タイマーは必要ありません。 – vicky
私は同意します。それはあなたのウィンドウ - ソリューションは完璧です。 –