在OS3上部署时OS4上的MediaPlayer兼容性问题

时间:2010-06-21 04:04:16

标签: iphone media-player ios4

我的设备在OS4 GM上运行,播放时它不会出现Mediaplayer。当在os3.1.3上进行测试时,它运行良好。 当我的目标是在OS4上部署它将解决这个问题,我该如何解决它?

这是我的代码 .H

  #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2
MPMoviePlayerController *theMovie;
  #endif
//On a 4.0 device, implement the MPMoviePlayerViewController
  #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
MPMoviePlayerViewController *theMovie;
  #endif



//If iPhone OS is 3.1 or less, implement the MPMoviePlayerController
  #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2
@property (readwrite, retain) MPMoviePlayerController *theMovie;
  #endif
//On a 4.0 device, implement the MPMoviePlayerViewController
  #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
@property (readwrite, retain) MPMoviePlayerViewController *theMovie;
  #endif

的.m

 #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2

                    NSLog(@"__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_3_2");

                    AppDelegate = nil;

                    AppDelegate = [[UIApplication sharedApplication] delegate];

                    [AppDelegate ForceHideNavigationBar];

                    theMovie = nil;

                    // Register to receive a notification that the movie is now in memory and ready to play

                    [[NSNotificationCenter defaultCenter] addObserver:self 

                                                                       selector:@selector(moviePreloadDidFinish:) 

                                                                            name:MPMoviePlayerContentPreloadDidFinishNotification 

                                                                         object:theMovie];



                    // Register to receive a notification when the movie has finished playing. 

                    [[NSNotificationCenter defaultCenter] addObserver:self 

                                                                       selector:@selector(moviePlayBackDidFinish:) 

                                                                            name:MPMoviePlayerPlaybackDidFinishNotification 

                                                                         object:theMovie];



                    // Register to receive a notification when the movie scaling mode has changed. 

                    [[NSNotificationCenter defaultCenter] addObserver:self 

                                                                       selector:@selector(movieScalingModeDidChange:) 

                                                                            name:MPMoviePlayerScalingModeDidChangeNotification 

                                                                         object:theMovie];



                    theMovie = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:AppDelegate.PushLink]];

                    theMovie.scalingMode = MPMovieScalingModeAspectFill;
                    [theMovie play];



  #endif               

                    //On a 4.0 device, implement the MPMoviePlayerViewController

  #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2

                    // Initialize a movie player object with the specified URL

                    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:AppDelegate.PushLink]];

                    if (mp) {



                         self.theMovie = mp;

                         [mp release];

                         //Present

                         [self presentMoviePlayerViewControllerAnimated:theMovie];



                         // Play the movie!

                         self.theMovie.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

                         [self.theMovie.moviePlayer play];

                    }

  #endif

1 个答案:

答案 0 :(得分:3)

我想要同时定位iOS3和iOS4,你不想使用条件编译(#if语句)。条件编译在编译时解析,但您希望根据用户正在运行的系统在运行时中更改其行为。

你实际上想要使用“弱链接”。

  1. 将Base SDK设置为iOS4。设置 iPhone OS部署目标到iOS3
  2. 声明两个属性但在 您的代码检查if ([MPMoviePlayerViewController class] != nil)。如果不是nil,请使用 MPMoviePlayerViewController, 否则,请使用旧的。
  3. 有关弱链接的更多信息,请参阅: