-1

iPhoneシミュレーターで動画を再生したいです。MPMoviePlayerViewController を試してみましたが、再生されません。誰でもそれを行う方法について考えがありますか? 良いチュートリアルがあれば、見つけてください。ありがとう。

注: MPMoviePlayerController ではなく MPMoviePlayerViewController に関する質問

4

4 に答える 4

3

ビデオ ファイルを Xcode プロジェクトにドラッグ アンド ドロップするだけです。

"videourl" に動画の URL を指定します

NSURL *url = [NSURL URLWithString:videourl];
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];     
[self presentMoviePlayerViewControllerAnimated:moviePlayer1];

シミュレーターで完全に実行されます

このリンクも役立ちます

于 2012-09-03T10:00:56.290 に答える
2

次のコードを使用します

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];
于 2012-09-03T10:20:12.097 に答える
2

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];
}
于 2012-09-03T10:01:53.697 に答える
2

私のヘッダーファイルに次のように書きます:

MPMoviePlayerController *moviePlayer;

このプロパティで:

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;

そして、moviePlayer を初期化するメソッドでは:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;
于 2012-09-03T10:02:00.483 に答える