4
我在iPad上播放電影。如果我只是加載一個mp4文件,播放器不會自動啓動 - 但以m3u8爲例,它堅持自動啓動。有沒有人遇到過這個?難道我做錯了什麼?MPMoviePlayerController在流式傳輸時自動播放 - 我如何阻止它?
- (id)initWithVideo:(VideoDO*)video frame:(CGRect)rect {
NSURL* videoURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]; // With this URL, player starts automatically
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
moviePlayer.shouldAutoplay = NO;
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
moviePlayer.view.frame = rect;
moviePlayer.view.backgroundColor = [UIColor blackColor];
[moviePlayer prepareToPlay];
self.view = moviePlayer.view;
[moviePlayer stop];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieChangedLoadState:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];
return self;
}
看來這只是它的方式 - 對於流式視頻,「shouldAutoplay」不起作用。該解決方案可能首先加載視頻縮略圖,然後在用戶單擊縮略圖後開始流式傳輸。 – Matz 2010-08-09 09:52:39
在這裏你可以做[moviePlayer pause];而不是[moviePlayer停止];並刪除該行[moviePlayer prepareToPlay];從代碼,它會工作。讓我知道是否有問題。 – AppAspect 2011-06-20 17:53:08