0

我的设备在 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
4

1 回答 1

3

我想同时针对 iOS3 和 iOS4,您不想使用条件编译(#if语句)。条件编译在编译时解决,但您想要一些可以根据用户正在运行的系统在运行时改变其行为的东西。

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

  1. 将您的 Base SDK 设置为 iOS4。将 iPhone OS 部署目标设置为 iOS3
  2. 声明这两个属性,但在您的代码检查if ([MPMoviePlayerViewController class] != nil)中。如果不是nil,请使用 MPMoviePlayerViewController,否则,请使用旧的。

有关弱链接的更多信息,请参阅:

于 2010-06-21T05:49:13.213 回答