MPMoviePlayerController のサイズを変更するにはどうすればよいですか? フルスクリーンで再生したくありません。ビデオが再生されているビューの一部が必要です。いろいろ調べましたが、いい答えが見つかりませんでした。
ありがとう
MPMoviePlayerController のサイズを変更するにはどうすればよいですか? フルスクリーンで再生したくありません。ビデオが再生されているビューの一部が必要です。いろいろ調べましたが、いい答えが見つかりませんでした。
ありがとう
Try this sample,
Import #import <MediaPlayer/MediaPlayer.h>
in your header file and include MediaPlayer framework in your project .
- (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];
}