Проблема с медиаплеером на базе iOS4 и развертыванием iOS3 - PullRequest
3 голосов
/ 22 июня 2010

при запуске на устройстве 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];

                }

Ответы [ 2 ]

15 голосов
/ 25 июня 2010

Я делаю очень похожую вещь в своем приложении, которое использует 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];



        }

    }

Надеюсь, это поможет !!

0 голосов
/ 08 июля 2010
[[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

Однако он завершает работу после завершения фильма, поскольку необходимо создать метод для уведомления.Также вам нужно выпустить фильм, чтобы можно было обнаружить утечку памяти.

...