iPhoneシミュレーターで動画を再生したいです。MPMoviePlayerViewController を試してみましたが、再生されません。誰でもそれを行う方法について考えがありますか? 良いチュートリアルがあれば、見つけてください。ありがとう。
注: MPMoviePlayerController ではなく MPMoviePlayerViewController に関する質問
iPhoneシミュレーターで動画を再生したいです。MPMoviePlayerViewController を試してみましたが、再生されません。誰でもそれを行う方法について考えがありますか? 良いチュートリアルがあれば、見つけてください。ありがとう。
注: MPMoviePlayerController ではなく MPMoviePlayerViewController に関する質問
ビデオ ファイルを Xcode プロジェクトにドラッグ アンド ドロップするだけです。
"videourl" に動画の URL を指定します
NSURL *url = [NSURL URLWithString:videourl];
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer1];
シミュレーターで完全に実行されます
このリンクも役立ちます
次のコードを使用します
MPMoviePlayerController *moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:yourVideoURL];
moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer1];
[moviePlayer1 play];
ARCを想定。
たとえば、viewDidLoad メソッドでそれを呼び出し、次を使用してそのコントローラーをビューに追加できます。
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"test" ofType:@"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
[self.view addSubview:theMovie.view];
[self addChildViewController:theMovie];
}
私のヘッダーファイルに次のように書きます:
MPMoviePlayerController *moviePlayer;
このプロパティで:
@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;
そして、moviePlayer を初期化するメソッドでは:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;