How to output video on external display with controls on ipad?

本秂侑毒 提交于 2020-01-01 07:09:06

问题


Currently when outputting video to an external display from the iPad, it moves the controls and all to the external display. This is not useful because you cannot control the movie while the controls are on the external display. Here are some code snippets from our app.

This is the screen setup code: (A method called 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];
}

This is the creation of the MPMoviePlayerViewController:

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

I also have a MPMoviePlayerController and have also tried this:

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];

Currently with the 2nd implementation, adding to both the self.view and the external_window it will show the video on the external display(with controls) and the iPad screen looks like nothing is happening other than the status bar disappearing when the movie controls fade out. I have also tried adding the moviePlayer.view to just self.view and it will flicker something to the effect of "showing content on tv" message before it then proceeds to play the movie on the iPad. Currently the video is launched by pressing a button. Using the simulator and the TV Out option as it's easier to debug. Xcode version 3.2.5 and the latest version of iOS on an actual device. How can this be fixed? It should behave like the youtube app on iPad.


回答1:


The easy way to do this is with a UIWebView. It will automatically detect the external monitor, and display the video there, while keeping the standard playback controls on the device.

Here's some sample code:

- (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]];      
}


来源:https://stackoverflow.com/questions/4621293/how-to-output-video-on-external-display-with-controls-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!