0
如何更改MPMoviePlayerController的大小? 我不想讓它在全屏播放,我只想要視頻的一部分播放視頻。我搜查了很多,但我找不到一個好的答案。MPMoviePlayerController的大小
感謝
如何更改MPMoviePlayerController的大小? 我不想讓它在全屏播放,我只想要視頻的一部分播放視頻。我搜查了很多,但我找不到一個好的答案。MPMoviePlayerController的大小
感謝
嘗試用你的尺寸來初始化播放器,然後禁用控制:
-(void) configurePlayer {
self.moviePlayer = [[MPMoviePlayerController alloc] init];
[self.moviePlayer setControlStyle:MPMovieControlStyleNone];
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[self.moviePlayer setMovieSourceType:(MPMovieSourceTypeStreaming)];
CGRect frame = CGRectMake(yourX, yourY, yourWidth, yourHeight);
[self.moviePlayer.view setFrame:frame]; // player's frame must match parent's
[self.view addSubview: self.moviePlayer.view];
[self.view bringSubviewToFront:self.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(metadataUpdate:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
}
用於播放使用這種方法
-(void) playStream {
NSURL *url = [NSURL URLWithString:@"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"];
[self.moviePlayer setContentURL:url];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
}
試試這個樣本, 導入#import <MediaPlayer/MediaPlayer.h>
在你的頭文件並將MediaPlayer框架包含在您的項目中。
- (IBAction)testVideoAction:(id)sender {
NSURL *movieURL = [NSURL URLWithString:@"http://www.tools4movies.com/dvd_catalyst_profile_samples/Harold%20Kumar%203%20Christmas%20bionic.mp4"];
MPMoviePlayerViewController *movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
movieController.view.frame = CGRectMake(10, 10, 300, 300);
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
[view addSubview:movieController.view];
[self.view addSubview:view];
[movieController.moviePlayer play];
}
謝謝,它的工作,但視頻不播放,mpmovieplayercontroller是黑色 – user2401621
現在看,我已經更正了答案。 – protikhonoff
首先你必須配置播放器,然後使用 - (void)playStream方法 – protikhonoff