2012-07-30 32 views
1

我有一段短片用於循環播放視圖的背景。我使用MPMoviePlayerController播放電影。 repeatMode被設置爲MPMovieRepeatModeOne,並且這在iPad 2,3和模擬器中正常工作。然而,在iPad 1上,電影會循環一次,並在第二次播放後立即停止播放。該項目是iOS 5 w/o ARC(從GM測試到5.1.1)。MPMoviePlayerController不在iPad 1上循環播放iOS 5

- (void)loadVideo { 
    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"movieFileName.m4v" ofType:nil]; 
    self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:urlStr]]; 
    self.videoPlayer.controlStyle = MPMovieControlStyleNone; 
    self.videoPlayer.scalingMode = MPMovieScalingModeFill; 
    self.videoPlayer.repeatMode = MPMovieRepeatModeOne; 
    self.videoPlayer.view.userInteractionEnabled = NO; 
    [self.videoPlayer.view setFrame:self.movieContainer.bounds]; 
    [self.movieContainer addSubview:self.videoPlayer.view]; 
} 

我怎樣才能讓電影在iPad 1上循環播放?

+0

我已經有了答案,但我必須等待8個小時回答我自己的問題,因爲我有不到10個東西。請耐心等待。答案的本質是:您必須收聽MPMoviePlayerPlaybackStateDidChangeNotification。 – 2012-07-30 13:42:18

回答

1

嘗試了很多之後,我終於找到了解決這個問題:

的改變的播放狀態MPMoviePlayerPlaybackStateDidChangeNotification的通知註冊後,電影不休循環,並在iPad上第二回放後不會停止1.請記住,這種行爲不會發生在iPad 2,3或Simulator上。

爲通知執行的選擇器不能爲空。只需分配一個布爾或其他東西。從上面的擴展代碼將是:

- (void)loadVideo { 
    // Create the controller 
    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"movieFileName.m4v" ofType:nil]; 
    NSURL *url = [NSURL fileURLWithPath:urlStr]; 
    self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 

    // Configure the controller 
    self.videoPlayer.controlStyle = MPMovieControlStyleNone; 
    self.videoPlayer.scalingMode = MPMovieScalingModeFill; 
    self.videoPlayer.repeatMode = MPMovieRepeatModeOne; 
    self.videoPlayer.view.userInteractionEnabled = NO; 
    [self.videoPlayer.view setFrame:self.movieContainer.bounds]; 

    // Register for notifications 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerNotification:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:videoPlayer]; 
    self.listeningToMoviePlayerNotifications = YES; 

    // Add its view to the hierarchy 
    [self.movieContainer addSubview:self.videoPlayer.view]; 
} 

- (void)moviePlayerNotification:(NSDictionary *)userInfo { 
    // Do anything here, for example re-assign the listeningToMoviePlayerNotification-BOOL 
    self.listeningToMoviePlayerNotifications = YES; 
} 
相關問題