簡體   English   中英

基於iOS4並部署iOS3的Media Player存在問題

[英]A problem with Media Player base on iOS4 and deploy iOS3

當在Device 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];

                }

我在我的應用程序上做了一個非常類似的事情,它使用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];



        }

    }

希望這可以幫助!!

[[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

但是,一旦電影完成,它就會退出,因為您必須為通知創建方法。 此外,您需要在那里發布電影,以便您可以捕獲內存泄漏。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM