iPhone - 在 3.0 和 4.0 OS/SDK 上播放视频吗?

发布于 2024-08-30 04:51:34 字数 154 浏览 6 评论 0原文

从 3.2 iPhone OS SDK 开始,播放视频确实有所不同。

所以我想知道是否有一种方法可以使用兼容的代码(<和>3.2)使视频全屏播放,而无需为这两种情况编写代码。

我想我们必须编写 2 个版本的类来处理视频播放……

你的!

Since 3.2 iPhone OS SDK, playing a video is really different.

So I was wondering if there is a way to make video play in full screen with a compatible code (both < and >3.2) without writing code for the two cases.

I think we'll have to write 2 versions of our classes handling video playing...

Thy !

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

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

发布评论

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

评论(3

暮光沉寂 2024-09-06 04:51:34

我基本上按照上面 Jeff Kelly 的建议在 3.1 及更高版本上运行,注意instancesRespondToSelector 调用:

// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];


    //Will only run this code for >= OS 3.2 
    if ([MPMoviePlayerController instancesRespondToSelector:@selector(setFullscreen:animated:)]){   

        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayBackStateDidChange:) 
                                                     name:MPMoviePlayerPlaybackStateDidChangeNotification 
                                                   object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(nowPlayingMovieDidChange:) 
                                                     name:MPMoviePlayerNowPlayingMovieDidChangeNotification 
                                                   object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayBackDidFinish:) 
                                                     name:MPMoviePlayerDidExitFullscreenNotification 
                                                   object:nil];

        mp.controlStyle = MPMovieControlStyleFullscreen;


        [mp setScalingMode:MPMovieScalingModeAspectFit];

                    //change mainMenu here to whatever your parent view is
        [mp.view setFrame:mainMenu.frame];
        [self.view addSubview:mp.view];



        [mp setFullscreen:YES animated:NO];
    }
//continue as normal

然后在 moviePlayBackDidFinish 函数中我使用相同的技术来删除通知。

I do basically what Jeff Kelly above suggests to run on 3.1 and above, note the instancesRespondToSelector call:

// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];


    //Will only run this code for >= OS 3.2 
    if ([MPMoviePlayerController instancesRespondToSelector:@selector(setFullscreen:animated:)]){   

        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayBackStateDidChange:) 
                                                     name:MPMoviePlayerPlaybackStateDidChangeNotification 
                                                   object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(nowPlayingMovieDidChange:) 
                                                     name:MPMoviePlayerNowPlayingMovieDidChangeNotification 
                                                   object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayBackDidFinish:) 
                                                     name:MPMoviePlayerDidExitFullscreenNotification 
                                                   object:nil];

        mp.controlStyle = MPMovieControlStyleFullscreen;


        [mp setScalingMode:MPMovieScalingModeAspectFit];

                    //change mainMenu here to whatever your parent view is
        [mp.view setFrame:mainMenu.frame];
        [self.view addSubview:mp.view];



        [mp setFullscreen:YES animated:NO];
    }
//continue as normal

and then later in the moviePlayBackDidFinish function I use the same technique to remove the notifications.

稳稳的幸福 2024-09-06 04:51:34

一种可能性是为此提供一个辅助方法。这样,您只需要编写一次,就可以在任何地方都拥有这种功能。

要编写辅助方法本身,您需要检查 MPMoviePlayerViewController 是否可用。如果是这样,请使用它,然后全屏显示它。否则只需使用常规的 MPMoviePlayerController。

所以基本框架是:

-(void)playMovie:(NSURL *)movieURL
{
    Class mpVC = NCClassFromString("MPMoviePlayerViewController");
    if(mpVC)
    {
        // Generate MPPlayerViewController here and use accordingly
    }
    else
    {
        // Generate MPPlayerController here and use accordingly
    }
}

One possibility is to have a helper method for this. This way you'll only need to write once and have this capability everywhere.

To write the helper method itself, you'll want to check if MPMoviePlayerViewController is available. If so, use that, and then present that fullscreen. Otherwise just use the regular MPMoviePlayerController.

So the basic framework would be:

-(void)playMovie:(NSURL *)movieURL
{
    Class mpVC = NCClassFromString("MPMoviePlayerViewController");
    if(mpVC)
    {
        // Generate MPPlayerViewController here and use accordingly
    }
    else
    {
        // Generate MPPlayerController here and use accordingly
    }
}
流殇 2024-09-06 04:51:34

您可能必须使用#if/#else/#endif 块并编译一个通用二进制文件,该二进制文件具有适合特定操作系统级别的正确可执行文件。

You may have to use #if/#else/#endif blocks and compile a Universal Binary which has the right executable for the particular O/S level.

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