2

このコードをviewDidLoadメソッドに追加しました:

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"myvid" ofType:@"m4v"];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];

    MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    moviePlayer.controlStyle = MPMovieControlStyleNone;
    [self.view insertSubview: moviePlayer.view aboveSubview: self.view];
    [moviePlayer play];

うまくいきません!iOS のビューのバックグラウンドでビデオを再生するにはどうすればよいですか? (ストーリーボードを使用)

4

1 に答える 1

2

作成した MPMoviePlayerController のインスタンスは、再生中に ARC によって損傷を受けたようです。

MPMoviePlayerController の strong プロパティを作成し、そこに作成したインスタンスを割り当ててから再生を開始してみてください。

したがって、コードは次のようになります

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"myvid" ofType:@"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];

self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
//set the frame of movie player
self.moviePlayer.view.frame = CGRectMake(0, 0, 200, 200);
[self.view addSubView:self.moviePlayer.view];
[self.moviePlayer play];
于 2013-03-25T17:52:04.007 に答える