A problem with Media Player base on iOS4 and deploy iOS3

前端 未结 2 422
鱼传尺愫
鱼传尺愫 2020-12-24 00:17

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?

相关标签:
2条回答
  • 2020-12-24 00:28
    [[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];
    

    This code will work in iOS4

    It however does quit once the movie completes because you must create the method for the notification. Also you need to release the movie there so that you can catch the memory leak.

    0 讨论(0)
  • I am doing a very similar thing on my app which is using 4.0 as the base SDK and yet I am targeting iOS3 devices too. I had to check the OS version to properly provide the right code for the video playback. For example:

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

    Hope this helps!!

    0 讨论(0)
提交回复
热议问题