5

从 3.2 iPhone OS SDK 开始,播放视频真的不一样了。

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

我认为我们必须编写 2 个版本的类来处理视频播放......

你!

4

3 回答 3

2

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

// 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 函数中,我使用相同的技术来删除通知。

于 2010-07-28T03:24:34.670 回答
0

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

要编写辅助方法本身,您需要检查 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
    }
}
于 2010-07-26T20:12:39.883 回答
-1

您可能必须使用 #if/#else/#endif 块并编译具有特定 O/S 级别的正确可执行文件的通用二进制文件。

于 2010-04-21T09:57:46.613 回答