2010-06-21 59 views
0

我的設備在OS4 GM上運行,並且在播放時不顯示Mediaplayer。在os3.1.3上測試時效果很好。 當我的目標是在OS4上部署它將解決這個問題,我該如何解決它?在OS3上部署時,OS4上的MediaPlayer兼容性問題

這裏是我的代碼 .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 

回答

3

我要同時針對IOS3和iOS4的,你不想使用條件編譯(#if語句) 。條件編譯在編譯時解析,但您希望根據用戶正在運行的系統在運行時上更改其行爲。

你實際上想使用「弱鏈接」。

  1. 將您的Base SDK設置爲iOS4。設置 iPhone操作系統部署目標IOS3
  2. 聲明性能,但 代碼檢查if ([MPMoviePlayerViewController class] != nil)。如果不是nil,則使用 MPMoviePlayerViewController, ,否則使用舊的。

更多關於弱鏈接,請參閱:

+0

感謝馬特·加拉格爾 – RAGOpoR 2010-06-21 07:45:10

+0

我有當,當上OS3部署它有一定的誤差整合iAd的問題像這樣***由於未捕獲的異常'NSInvalidUnarchiveOperationException'而終止應用程序,原因:'*** - [NSKeyedUnarchiver decodeObjectForKey:]:無法解碼類的對象(ADBannerView)' – RAGOpoR 2010-06-21 10:36:52