iPadにコントロールを使用して外部ディスプレイにビデオを出力する方法は?

StackOverflow https://stackoverflow.com/questions/4621293

  •  30-09-2019
  •  | 
  •  

質問

現在、iPadから外部ディスプレイにビデオを出力すると、コントロールとすべてが外部ディスプレイに移動します。コントロールが外部ディスプレイ上にある間に映画を制御できないため、これは役に立ちません。アプリのコードスニペットを次に示します。

これは画面セットアップコードです:( setupExternalScreenと呼ばれる方法)

if ([[UIScreen screens] count] > 1) {
    external_disp = [[UIScreen screens] objectAtIndex:1];
    [external_disp setCurrentMode:[[external_disp availableModes] objectAtIndex:0]];
    self.external_window = [[UIWindow alloc] init];
    external_window.screen = external_disp;
    [external_window makeKeyAndVisible];
}

これは、mpmovieplayerviewcontrollerの作成です。

[self setupExternalScreen]; //Calls the code above
MPMoviePlayerViewController *mpv = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:mpv];

また、mpmovieplayercontrollerもあり、これも試しました。

self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerDidFinish:) name:MPMoviePlayerDidExitFullscreenNotification object:[self moviePlayer]];
[self.view addSubview:moviePlayer.view];

if (!external_window) {
    [self setupExternalScreen];
}
if (external_window) {
    [external_window addSubview:moviePlayer.view];
} 
[moviePlayer setControlStyle:MPMovieControlStyleDefault];

[moviePlayer setFullscreen:YES];// animated:NO];

if (![moviePlayer isPreparedToPlay]) [moviePlayer prepareToPlay];
[moviePlayer play];

現在、2回目の実装により、self.viewとexternal_windowの両方に追加外部ディスプレイにビデオが表示され(コントロール付き)、iPad画面は、映画コントロールがフェードアウトすると、ステータスバーが消える以外に何も起きていないように見えます。 。また、MoviePlayer.ViewをSelf.Viewに追加しようとしました。それは、「テレビでコンテンツを表示する」という効果を発生させてから、iPadで映画を再生します。現在、ビデオはボタンを押して起動しています。シミュレータとテレビのアウトオプションを使用して、デバッグが簡単になります。 Xcodeバージョン3.2.5および実際のデバイス上のiOSの最新バージョン。これはどのように修正できますか? iPadのYouTubeアプリのように動作するはずです。

役に立ちましたか?

解決

これを行う簡単な方法は、uiwebviewを使用することです。標準の再生コントロールをデバイスに保持しながら、外部モニターを自動的に検出し、そこにビデオを表示します。

サンプルコードは次のとおりです。

- (void)embedInternalVideo:(CGRect)frame {
    NSBundle *bundle = [NSBundle mainBundle];
    NSString* html = @"<video src=\"sample_iPod.m4v\" width=640 height-480 controls autoplay></video>";
    if (videoView == nil) {  
        videoView = [[UIWebView alloc] initWithFrame:frame];  
        [self.view addSubview:videoView];  
    }  
    [videoView loadHTMLString:html baseURL:[bundle resourceURL]];      
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top