如何更改 MPMoviePlayerController 的大小?我不想让它全屏播放,我只想要视频正在播放的视图的一部分。我已经搜索了很多,但我找不到一个好的答案。
谢谢
如何更改 MPMoviePlayerController 的大小?我不想让它全屏播放,我只想要视频正在播放的视图的一部分。我已经搜索了很多,但我找不到一个好的答案。
谢谢
试试这个示例,#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];
}
尝试使用您的尺寸初始化播放器,然后禁用控件:
-(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];
}