0

MPMoviePlayerController を使用して約 1 週間、ビデオを再生しようとしましたが、ほとんど成功しませんでした。ようやくビデオをロードする段階に到達しました(または、少なくともビデオの長さを教えてくれるので、そうすると思います)。

ただし、私のビデオは再生可能にならないため、黒い四角が表示されます。

私のコードは次のとおりです。

  - (void)loadMovieWithURL:(NSURL *)movieURL
{
    NSLog( @"Video URL = '%@'", [movieURL path]);
    NSData *data = [NSData dataWithContentsOfURL:movieURL];
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayerPlaybackStateDidChange:)  name:MPMoviePlayerPlaybackStateDidChangeNotification  object:nil];

    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] init];
    self.moviePlayer = mp;
    [self.moviePlayer.view setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [self addSubview:self.moviePlayer.view];
    [self.moviePlayer setContentURL:movieURL];
    self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [self.moviePlayer setFullscreen:NO];
    [self.moviePlayer setScalingMode:MPMovieScalingModeFill];
    [self.moviePlayer setControlStyle:MPMovieControlStyleNone];

    //[self.moviePlayer setShouldAutoplay:YES];

    [self.moviePlayer prepareToPlay];
    [self.moviePlayer play];

}

私はそれらをチェックするためだけに NSLog に多くの値を出力しています。

2013-01-07 15:33:39.858 WildMap_iOS[9887:16703] Video URL = '/Users/elliott/Library/Application Support/iPhone Simulator/6.0/Applications/A233395A-3E8F-4E35-BF42-09D9B743EA33/test.3gp'
    2013-01-07 15:33:40.100 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Disabling autoplay for pause
    2013-01-07 15:33:40.101 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Disabling autoplay
    2013-01-07 15:33:40.176 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Enabling autoplay
    2013-01-07 15:33:40.179 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
    2013-01-07 15:33:40.180 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
    2013-01-07 15:33:40.181 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
    2013-01-07 15:33:40.182 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
    2013-01-07 15:33:40.259 WildMap_iOS[9887:16703] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
    2013-01-07 15:33:40.401 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Enabling autoplay
    2013-01-07 15:33:41.344 WildMap_iOS[9887:16703] Is ready to display 0
    2013-01-07 15:33:41.344 WildMap_iOS[9887:16703] Duration: 45.267000

MPMoviePlayerLoadStateDidChangeNotification を確認する通知を設定しましたが、変更されません。誰かが同様の問題を抱えていましたか、または私のコードの何が問題なのか知っていますか? さらに情報が必要な場合は、お気軽にお問い合わせください。

EDIT 1 (ダンのコードのテスト)

以下を使用する場合:

    NSLog( @"Video URL = '%@'", [movieURL path]);
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.view.frame = self.bounds;
[self addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];

//NSData *data = [NSData dataWithContentsOfURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayerPlaybackStateDidChange:)  name:MPMoviePlayerPlaybackStateDidChangeNotification  object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerLoadStateChanged:)
                                             name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

私のログは次のとおりです。

2013-01-08 12:08:16.105 WildMap_iOS[705:16703] [MPAVController] Autoplay: Disabling autoplay for pause
2013-01-08 12:08:16.105 WildMap_iOS[705:16703] [MPAVController] Autoplay: Disabling autoplay
2013-01-08 12:08:16.138 WildMap_iOS[705:16703] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2013-01-08 12:08:16.144 WildMap_iOS[705:16703] [MPAVController] Autoplay: Enabling autoplay
2013-01-08 12:08:16.153 WildMap_iOS[705:16703] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2013-01-08 12:08:16.153 WildMap_iOS[705:16703] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2013-01-08 12:08:16.157 WildMap_iOS[705:16703] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2013-01-08 12:08:16.177 WildMap_iOS[705:16703] [MPAVController] Autoplay: Enabling autoplay
2013-01-08 12:08:17.244 WildMap_iOS[705:16703] Is ready to display 0
2013-01-08 12:08:17.244 WildMap_iOS[705:16703] Duration: 45.267000

そのため、moviePlayerLoadStateChanged が呼び出されない元のコードと同じようです。ただし、MPMoviePlayerController がビデオを読み込めない場合にビデオの長さを取得する方法については、まだ混乱していますか? これはコーデックの問題でしょうか? ダウンロード後にビデオがまったく機能するかどうかを確認する方法はありますか?

編集2:

これはコーデックの問題の可能性があるようです。私は今、2つの同様のURL、1 mov / 1 3gpで試しました.mov 1は音声で再生されますが、ビデオは再生されません. これを機能させる方法、またはより多くのタイプがサポートされている別のムービープレーヤーを提案できますか?

4

1 に答える 1

0

すべてのセットアップ コードを次のように置き換えてみてください。

// get the url as moveURL
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];

// notice what notification we subscribe to...
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerLoadStateChanged:)
                                             name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

状態の変化を moviePlayerLoadStateChanged: に記録します。それでもうまくいかない場合は、おそらく URL に問題があります。

于 2013-01-07T15:50:04.363 に答える