0

MPMoviePlayerController を使用してビデオを表示しようとしていますが、うまく動作させることができません。私のビデオは私のサーバーにあります。だから私はこのように表示しようとしています:

-(void) playMovieAtURL: (NSURL*) theURL {
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
    moviePlayer.view.frame = self.view.bounds;
    moviePlayer.controlStyle = MPMovieControlModeDefault;
    moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    moviePlayer.fullscreen = YES;

    [self.view addSubview:moviePlayer.view];
    [moviePlayer prepareToPlay];
    [moviePlayer play];
}

moviePlayer は、viewController のプロパティです。指定された URL は正しいです (サファリでテスト済み)。私の動画は .mov 動画です。

関数が呼び出されると、黒い画面が表示されます。コントロールが表示されず、アプリのステータス バーにネットワーク アクティビティ インジケーターが表示されないため、ビデオが読み込まれないと思います。

どんな助けでも大歓迎です。

編集

デバイスのサファリアプリからビデオにアクセスしようとすると、次の結果になることに気付きました:ここに画像の説明を入力

編集2

私の動画は 480 × 850 で、MPMoviePlayerController は 640 × 480 までの動画しかサポートしていないため、このフレームワークでは再生できません。ビデオのサイズを変更する必要がありますか? または、ビデオを表示するために使用できる別のフレームワークはありますか? 私は非常にシンプルなプレーヤーが必要です...

4

2 に答える 2

1

// このようにできます

 -(void)playMovie:(id)sender
 {
   NSURL *url = [NSURL URLWithString:
  @"http://www.xxxx.com/movie.mov"];

_moviePlayer =  [[MPMoviePlayerController alloc]
             initWithContentURL:url];

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

_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];

}

// ターゲット アクション通知メソッド

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
   MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
  removeObserver:self
  name:MPMoviePlayerPlaybackDidFinishNotification
  object:player];

if ([player
    respondsToSelector:@selector(setFullscreen:animated:)])
{
    [player.view removeFromSuperview];
}
}
于 2013-07-03T10:29:49.043 に答える
1

このようにしてください:

-(void)playMovieAtURL:: (NSURL*) url
{

    moviePlayer =  [[MPMoviePlayerController alloc]
                 initWithContentURL:url];

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

    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:moviePlayer.view];
    [moviePlayer setFullscreen:YES animated:YES];
    [moviePlayer play];
    [self.view bringSubviewToFront:moviePlayer.view];
}


- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    MPMoviePlayerController *player = [notification object];
    [[NSNotificationCenter defaultCenter] 
      removeObserver:self
      name:MPMoviePlayerPlaybackDidFinishNotification
      object:player];

    if ([player
        respondsToSelector:@selector(setFullscreen:animated:)])
    {
        [player.view removeFromSuperview];
    }
}
于 2013-07-03T10:22:26.613 に答える