【问题标题】:A problem with Media Player base on iOS4 and deploy iOS3基于 iOS4 和部署 iOS3 的媒体播放器出现问题
【发布时间】:2010-06-22 10:12:48
【问题描述】:

在设备 3.1.2 上运行时,为什么它也会通过 if(NSClassFromString(@"MPMoviePlayerViewController") != nil) 并且做iOS4的代码然后它会崩溃,如何解决这个问题?

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

                }

【问题讨论】:

    标签: iphone media-player ios4


    【解决方案1】:

    我在使用 4.0 作为基础 SDK 的应用程序上做了非常相似的事情,但我也针对 iOS3 设备。我必须检查操作系统版本才能正确地为视频播放提供正确的代码。例如:

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

    希望这会有所帮助!

    【讨论】:

    • 这是一个巨大的帮助。谢谢你!
    • 非常感谢!它拯救了我的一天!
    【解决方案2】:
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) 
            name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    
      NSString *movpath = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
      MPMoviePlayerViewController* mpviewController = [[MPMoviePlayerViewController alloc] 
                          initWithContentURL:[NSURL fileURLWithPath:movpath]];
      [window addSubview:mpviewController.view];
            [window makeKeyAndVisible];
      MPMoviePlayerController *mp = [mpviewController moviePlayer];
      [mp prepareToPlay];
      [[mpviewController moviePlayer] play];
    

    此代码适用于 iOS4

    但是,一旦电影完成,它就会退出,因为您必须为通知创建方法。此外,您还需要在此处发布电影,以便捕获内存泄漏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多