2011-03-27 40 views
0
-(void)playVideo:(NSURL *)url{ 

    if (videoPlayer) { 
     [videoPlayer release]; 
     videoPlayer = nil; 
    } 
    videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
    url = nil; 
    videoPlayer.moviePlayer.controlStyle=MPMovieControlStyleFullscreen; 
    videoPlayer.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
    videoPlayer.moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
    videoPlayer.view.backgroundColor = [UIColor blackColor]; 


    [[UIApplication sharedApplication] 
    setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO]; 


    [videoPlayer.moviePlayer prepareToPlay]; 
    videoPlayer.moviePlayer.shouldAutoplay = YES; 
    videoPlayer.hidesBottomBarWhenPushed = YES; 
    self.navigationController.navigationBarHidden=NO; 
    videoPlayer.navigationItem.hidesBackButton = YES; 
    [self.navigationController pushViewController:videoPlayer animated:YES]; 

    [self addObservers]; 
} 

任何人都可以說這個代碼有什麼問題嗎?該網址是流式HTTP鏈接。視頻播放器正在出現,但過了一段時間它消失了。它是工作在3G網絡,但沒有wifi的MPMoviePlayerViewController不在iPod和iPhone

+0

您是否只開發4.0及以上版本? – shannoga 2011-03-27 10:55:39

+0

是的,它適用於4.o及以上..有趣的因素是3G網絡中的視頻播放,但Wi-Fi無法播放。 – Raj 2011-03-27 11:05:10

回答

1

正如你說,這是工作在3G上,但沒有Wi-Fi網絡,您的問題很可能與代碼無關,而與您正在測試的電影文件無關。

確保m3u8-snippet是完整的並且對於低帶寬也有效。如Best Practice GuideTechNote所述,用Apples Mediastream Validator測試m3u8。

+0

感謝您直到,問題是與WiFi網絡,它在其他WiFi連接中工作正常,感謝您提醒可能性 – Raj 2011-04-19 07:45:14

-1

後這一行:

videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 

補充一點:

[videoPlayer retain]; 
+0

感謝您的迴應,但它仍然無法正常工作 – Raj 2011-03-27 10:31:21