2014-03-13 26 views
0

我需要在一層UIView上播放MPMoviePlayerController。但只有聲音出來,沒有視頻。MPMoviePlayerController空白層

theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; 
[theMovie prepareToPlay]; 

theMovie.view.frame = CGRectMake(0, 0, 200, 150); 
[theMovie setControlStyle:MPMovieControlStyleDefault]; 
[theMovie setFullscreen:NO animated:YES]; 
theMovie.shouldAutoplay = YES; 
[theMovie setContentURL:movieURL]; 

[self addSubview:theMovie.view]; 
[theMovie play]; 

我只有黑屏,只有音頻。這是因爲我調用UIView作爲圖層,而不是子視圖?因爲我的要求是將UIView作爲圖層調用。

回答

0

它看起來不錯,你可以添加以下:

[_openingMovie setMovieSourceType:MPMovieSourceTypeStreaming]; 

希望這有助於

編輯

嘗試設置類似下面的SourceType中後設定的contentURL,

moviePlayerController_ = [[MPMoviePlayerViewController alloc] init]; 
moviePlayerController_.movieSourceType = MPMovieSourceTypeStreaming; 
[moviePlayerController_.moviePlayer setContentURL:url]; 

此代碼捕捉來自: An AVPlayerItem cannot be associated with more than one instance of AVPlayer'

+0

嗨,我有碰撞與訊息話題終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,理由是:「一個AVPlayerItem不能AVPlayer'.Thanks的多個實例相關聯.. – user3231429

+0

嘗試設置sourceType後設置的contentURL像下面的moviePlayerController_ = [[MPMoviePlayerViewController alloc] init]; moviePlayerController_.movi​​eSourceType = MPMovieSourceTypeStreaming; [moviePlayerController_.movi​​ePlayer setContentURL:url]; (來自:http://stackoverflow.com/questions/12041260/an-avplayeritem-cannot-be-associated-with-more-than-one-instance-of-avplayer) – MCMatan

+0

嗨,現在的崩潰消失了,但屏幕是仍然是空白的,只有音頻播放。感謝btw .. – user3231429