如何使用ipad上的控件将视频输出到外接显示器上?

发布于 2024-10-10 10:22:41 字数 1752 浏览 0 评论 0原文

目前,当从 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];

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空气里的味道 2024-10-17 10:22:41

最简单的方法是使用 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]];      
}

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]];      
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文