如何使用ipad上的控件在外部显示器上输出视频? [英] How to output video on external display with controls on ipad?

查看:311
本文介绍了如何使用ipad上的控件在外部显示器上输出视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,当从iPad输出视频到外部显示器时,它会将控件和所有控件移动到外部显示器。这没有用,因为当控件位于外部显示器上时,您无法控制电影。以下是我们的应用程序中的一些代码片段。

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.

这是屏幕设置代码:(一种名为setupExternalScreen的方法)

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

这是MPMoviePlayerViewController的创建:

This is the creation of the MPMoviePlayerViewController:

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

我还有一个MPMoviePlayerController并尝试过这个:

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

目前在第二个实现中,添加了self.view和external_window,它将显示视频在外部显示器(带控件)和iPad屏幕上看起来除了当电影控制淡出时状态栏消失以外什么也没发生。我还尝试将moviePlayer.view添加到self.view中,然后它会闪烁显示在电视上显示内容消息的效果,然后再继续在iPad上播放电影。目前,通过按下按钮启动视频。使用模拟器和TV Out选项,因为它更容易调试。 Xcode版本3.2.5和实际设备上的最新版iOS。怎么解决这个问题?它应该像iPad上的youtube应用程序一样。

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.

推荐答案

使用UIWebView可以轻松实现此目的。它将自动检测外部显示器,并在那里显示视频,同时保持设备上的标准播放控件。

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.

以下是一些示例代码:

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

这篇关于如何使用ipad上的控件在外部显示器上输出视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆