0

我試圖創建一個應用程序,該應用程序在視頻停止播放後顯示信息頁面。我看過這裏發佈的類似問題,並試圖實現它,但它仍然無法正常工作。我把一個NSLog放在movieFinishedCallback方法中,但是從來沒有出現過,所以我猜它甚至沒有被調用。有人能幫我弄明白嗎?MovieFinishedCallback通知未觸發

這裏是我的實現代碼...

-(IBAction)playvideo { 


    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
             pathForResource:@"sample" ofType:@"mov"]]; 

    MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] 
                initWithContentURL:url]; 

    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(movieFinishedCallback:)             
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:playercontroller]; 



    [self presentMoviePlayerViewControllerAnimated:playercontroller]; 

    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 


    [playercontroller.moviePlayer play]; 


    playercontroller = nil; 

} 


- (void) movieFinishedCallback:(NSNotification*) notification { 

    NSLog (@"The video ended"); 

    MPMoviePlayerController *player = [notification object]; 
    [[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:player];  
    player = nil; 


    View2 *second =[[View2 alloc] initWithNibName:nil bundle:nil]; 

    [self presentModalViewController:second animated:YES]; 

} 

回答

0

終於有了它的工作!我不知道這是否與MPMoviePlayerViewController沒有響應NSNotificationCenter這一事實有關,但我使用MPMoviePlayerController來顯示我的視頻,註冊了movieFinishedCallback的通知,然後使用movieFinishedCallback方法切換視圖。請參閱本教程以瞭解視頻播放http://www.techotopia.com/index.php/Video_Playback_from_within_an_iOS_5_iPhone_Application。唯一的事情是,現在視頻不會旋轉到風景!

0

我想你可能接到回訪電話時,電影已經完成,但是呈現視圖2時失敗。

View2是UIViewController的子類嗎?我無法看到如何通過將nil傳遞給initWithNibName:來獲得有效結果。我建議在movieFinishedCallback中使用NSLog來證明你到達那裏。然後NSLog(@「second =%@」,second);我的猜測是零。

修復的方法是加載一個視圖控制器真實的,或者使用一個有效的筆尖或從你的故事板...

// @"MainStoryboard" should be the name of the storyboard containing your VC 
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 

// @"SomeViewController" has to be set on the attributes inspector of the VC 
// in the storyboard 
SomeViewController *newVC = [storyboard instantiateViewControllerWithIdentifier:@"SomeViewController"]; 
[self presentModalViewController:newVC animated:YES]; 
+0

謝謝@danh!是的,View2是UIViewController的一個子類。我試圖在movieFinishedCallback中添加一個NSLog,它沒有顯示出來,所以它可能沒有被調用。視頻播放良好,但我也得到多個...「錯誤加載/系統/庫/擴展/音頻IPCDriver.kext /內容/ ...」,並在最後說,找不到函數指針NewDigiCoreAudioPlugIn工廠... (捆綁,未加載)。請幫忙? – skinnypinny 2012-08-01 14:08:06

+0

我想你可以在播放時忽略這些錯誤信息。廣泛報告模擬器問題。需要考慮在通知上發出呼叫。你能看看你是否可以得到loadstatechanged通知? – danh 2012-08-01 14:13:38

+0

那也沒有記錄任何東西。 :( – skinnypinny 2012-08-01 14:32:48