专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Iphone

一个关于Media Player 跨iPhone版本的有关问题

发布时间:2010-05-30 01:11:43 文章来源:www.iduyao.cn 采编人员:星星草
一个关于Media Player 跨iPhone版本的问题

when Run on Device 3.1.2, why it also pass if(NSClassFromString(@"MPMoviePlayerViewController") != nil) and do code of iOS4 then it will crash , how to fix this issues?
---------------------------------------------
 if(NSClassFromString(@"MPMoviePlayerViewController") != nil) {
                    // iOS 4 code
                    NSLog(@"MPMoviePlayerViewController");
                    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:AppDelegate.PushLink]];
                    if (mp) {
                        // save the movie player object
                        self.theMovie4 = mp;
                        [mp release];
                        //Present                       
                        [self presentMoviePlayerViewControllerAnimated:self.theMovie4];

                        // Play the movie!
                        self.theMovie4.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
                        [self.theMovie4.moviePlayer play];
                    }
                }
                else {
                    //iOS 3 Code
                    AppDelegate = nil;
                    AppDelegate = [[UIApplication sharedApplication] delegate];
                    [AppDelegate ForceHideNavigationBar];
                    theMovie3 = nil;
                    [[NSNotificationCenter defaultCenter] addObserver:self 
                                                             selector:@selector(moviePreloadDidFinish:) 
                                                                 name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                               object:theMovie3];
                    [[NSNotificationCenter defaultCenter] addObserver:self 
                                                             selector:@selector(moviePlayBackDidFinish:) 
                                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                                               object:theMovie3];
                    // Register to receive a notification when the movie scaling mode has changed. 
                    [[NSNotificationCenter defaultCenter] addObserver:self 
                                                             selector:@selector(movieScalingModeDidChange:) 
                                                                 name:MPMoviePlayerScalingModeDidChangeNotification 
                                                               object:theMovie3];
                    theMovie3 = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:AppDelegate.PushLink]];
                    [theMovie3 play];
                }
1 Answer
------------------------------------------
- (void) playMovieAtURL: (NSURL*) theURL {
    NSLog(@"playMovieAtURL");
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2 ) {
            NSLog(@"> 3.2");
            MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
            if (mp)
            {
                // save the movie player object
                //self.moviePlayerViewController = mp;
                //[mp release];
                [self presentMoviePlayerViewControllerAnimated:mp];
                mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
                [mp.moviePlayer play];
                [mp release];
            }
        } 
    else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
            NSLog(@"< 3.2");
            MPMoviePlayerController* theMovie = [[MPMoviePlayerController alloc] initWithContentURL: theURL];
            theMovie.scalingMode = MPMovieScalingModeAspectFill;
            // Register for the playback finished notification
            [[NSNotificationCenter defaultCenter]
             addObserver: self
             selector: @selector(myMovieFinishedCallback:)
             name: MPMoviePlayerPlaybackDidFinishNotification
             object: theMovie];
            // Movie playback is asynchronous, so this method returns immediately.
            [theMovie play];
        }
    }
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: