2012-10-30 95 views
1

我想在ios 6中播放視頻。我正在使用Xcode 4.5。我下面寫代碼,但得到錯誤在ios中播放視頻6

Test Demo[736:14003] [MPAVController] Autoplay: Disabling autoplay for pause 
Test Demo[736:14003] [MPAVController] Autoplay: Disabling autoplay 
Test Demo[736:14003] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0) 

和我的代碼

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"TestVideo" ofType:@"m4v"]; 
NSURL *streamURL = [NSURL fileURLWithPath:videoPath]; 

MPMoviePlayerController *player = 
[[MPMoviePlayerController alloc] initWithContentURL: streamURL]; 
[player prepareToPlay]; 
[player.view setFrame: self.view.bounds]; // player's frame must match parent's 
[self.view addSubview: player.view]; 
// ... 
[player play];` 
+0

http://stackoverflow.com/questions/12099393/cannot-play-video-with-mpmovieplayerviewcontroller –

回答

1

可能有很多問題,你的錯誤。

1)爲您的MPMoviePlayerController設置一個屬性併合成它。如果您的MPMoviePlayerController在播放前發佈,則可能會發生這種情況。

2)添加此代碼player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

3)每documentation,沒有提及.m4v擴展玩。

4)以下屏幕截圖將幫助您瞭解支持的格式。

enter image description here

1
NSString *url = [[NSBundle mainBundle] pathForResource:@"santaMessage" ofType:@"mp4"]; 

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; 

[self.view addSubview:moviePlayer.view]; 

moviePlayer.fullscreen = YES; 

moviePlayer.allowsAirPlay = YES; 

[moviePlayer play]; 

///這個工作就像一個魅力

+0

應該工作,但我做調試和網址是無 我做錯了什麼。 NSBundler不起作用 –