2015-05-19 25 views
-1

我知道這個問題可能會問。但我沒有找到解決方案。 我想通過MPMoviePlayerController播放視頻。我可以播放本地視頻。但問題是如何從互聯網播放視頻URL。 我已經搜索了答案。而且我知道我應該使用initWithContentURL方法。但這對我沒有幫助。視頻顯示爲黑色。MPMoviePlayerController與URL

我確定我的URL是視頻本身的link

這裏是我的代碼

moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"<MY video URL>"]]; 


// video player scalling 
moviePlayerController.scalingMode = MPMovieScalingModeAspectFill; 

moviePlayerController.controlStyle = MPMovieControlStyleDefault; 

// Set the frame for the video player view 
moviePlayerController.view.frame =CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height*3/5); 
[self.view addSubview:moviePlayerController.view]; 
+0

第一:'[NSURL URLWithString:@「<我的視頻URL>」]'是'null'?否則,URL的擴展名是什麼? 'MPMoviePlayerController'是否直接播放?您可能需要在該網址上完成一些工作,或者可能無法播放該類內容。 – Larme

+0

在這個問題上有20多個問題,你必須在詢問之前做一些研究。 – Vizllx

+0

@Larme視頻擴展是「3gp」,我試圖通過本地視頻播放這個視頻擴展,它成功播放 –

回答

-1

您需要一提的片源類型爲流。

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

[[NSNotificationCenter defaultCenter] addObserver:self 
           selector:@selector(moviePlaybackDidFinish:) 
            name:MPMoviePlayerPlaybackDidFinishNotification 
            object:nil];  

mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; 

[self presentMoviePlayerViewControllerAnimated:mpvc]; 
[mpvc.moviePlayer play]; 
相關問題