5

Apple「iPhoneのMoviePlayer」の例を調べました

mpmovieplayercontroller の上にオーバーレイしようとしていますが、

バンドルされているビデオクリップと完全に連携し、

しかし、URLからビデオをストリーミングするとうまくいきません。

オーバーレイ ビューはプレーヤーの後ろに隠れます。

オーバーレイ ビューを前面に表示する方法はありますか?

4

4 に答える 4

11

MPMoviePlayerController は、独自のウィンドウを作成し、それをキー ウィンドウとして設定します。これは、MoviePlayer サンプル アプリですでにご存知でしょう。

理由はわかりませんが、プレーヤーがストリームを使用するときに遅延が発生します。そのため、プレーヤーを初期化した直後に取得する keyWindow は、後で追加されるように見えるため、プレーヤーのウィンドウではない可能性があります。

「ごまかして」タイマーを使用して数秒後にプレーヤー ウィンドウを取得し、オーバーレイを追加できます。

[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(addMyOverlay:) userInfo:nil repeats:FALSE]

または、UIWindowDidBecomeKeyNotification イベントをリッスンして、同じことを行うことができます。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyWindowChanged:) name:UIWindowDidBecomeKeyNotification object:nil];

どちらのオプションも素晴らしいものではありません (これを行うためのよりクリーンな方法を知りたいです) が、仕事は完了します。

于 2009-09-06T23:04:12.547 に答える
3

「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];
    }
}
于 2010-03-31T17:08:19.077 に答える
2

非常に簡単な解決策:

appDelegate.window.backgroundColor = [UIColor clearColor];
appDelegate.window.windowLevel = 2;

これにより、アプリの UI がビデオ ウィンドウの上に表示されます。

私の投稿

于 2010-09-30T09:42:26.117 に答える
1

以前の回答はタイマーに基づいていました。& 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];
    }
}
于 2009-10-20T19:54:09.160 に答える