2

リソース ファイルから 25 秒の mp4 ムービーを読み込もうとしていますが、それを再生すると、MPMovieFinishReasonPlaybackEnded で MPMoviePlayerPlaybackDidFinishNotification セレクターがすぐに呼び出されます。再生状態をログに記録すると、次のように表示されます。

MPMoviePlaybackStatePlaying
MPMoviePlaybackStatePaused
MPMoviePlaybackStateStopped
MovieFinishReasonPlaybackEnded
MPMoviePlaybackStatePlaying
MPMoviePlaybackStatePaused

play メソッドは 1 回だけ呼び出しますが。誰かが私を助けてくれることを願っています。

-- 私のコードを表示するように編集:

MPMoviePlayerController* player = [[[MPMoviePlayerController alloc] initWithContentURL:movieURL] autorelease];

if (player)
{

    self.moviePlayerController = player;

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:player];

  [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerPlaybackStateDidChange:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:player];


    player.contentURL = movieURL;

    player.movieSourceType = MPMovieSourceTypeFile;

    player.controlStyle = MPMovieControlStyleNone;

    player.fullscreen = YES;

    switch (orientation) {
        case UIInterfaceOrientationLandscapeLeft:
            player.view.transform = CGAffineTransformMakeRotation(90.0f * (M_PI / 180.0f));
            break;
        case UIInterfaceOrientationLandscapeRight:
            player.view.transform = CGAffineTransformMakeRotation(-90.0f * (M_PI / 180.0f));
            break;
        default:
            break;
    }

    player.view.frame = self.view.bounds;

    [self.view addSubview:player.view];
}

[self.moviePlayerController play]
4

2 に答える 2

1

self.moviePlayerController保有物件ですか?そうでない場合、MPMoviePlayerControllerインスタンスは非常に迅速に (によってautorelease) 解放され、同様の動作が発生する可能性があります。

于 2012-09-12T13:52:07.147 に答える
0

コードをこれ以上見る必要がない場合は、再生できることがわかっている別のファイルを再生することをお勧めします。たとえば、次のサンプル プロジェクトからムービーを取得します: http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html再生されるかどうかを確認します。

適切にフォーマットされていないファイルを再生しようとしたときに、同様のことが起こりました。


うーん...何が悪いのかわかりません。movieURL が正しいことを確認しますか? どうやって手に入れますか?

記録のために、ここに私が映画をどのように提示するかを示しますが、あなたがしていることとまったく同じ効果はありません.

NSString *path = [[NSBundle mainBundle] pathForResource:movieFileName ofType:@"m4v"];

// If path is NULL (the resource does not exist) return to avoid crash
if (path == NULL)
    return;

NSURL *url = [NSURL fileURLWithPath:path];
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
mpViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
mpViewController.moviePlayer.shouldAutoplay = YES;

// NOTE: This can sometimes crash the app in the Simulator. This is a known bug
// in xcode: http://stackoverflow.com/a/8317546/472344
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController release];
于 2012-09-11T13:15:16.413 に答える