1

私のアプリケーションでは、次のコードを含むビューの1つでビデオを再生します

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bgVideo" ofType:@"mov"]];
        player = [[MPMoviePlayerController alloc] initWithContentURL:url];

        [player setControlStyle:MPMovieControlStyleNone];
        player.view.frame = CGRectMake(35, 190, 245, 156);
        [self.view addSubview:player.view];
        [player play];
        [player.view setBackgroundColor:[UIColor clearColor]];

私はviewWillAppearメソッドでこのコードを書きました

しかし、最初にこのビューに到達すると、MPMoviePlayerControllerは、ビデオを数分の1秒間開始する前に、黒い画面を表示します。

私は2番目の黒い画面が欲しくありません。

私はそれのために何をすべきですか?

よろしくお願いします。

4

1 に答える 1

0

たぶんプレイヤーは強力なプロパティを作成して合成します。出来た。

あなたの場合でもうまくいくはずです。

私の経験では、もう問題はありません。働けない方はご返信ください。


Edit

ちょっと間違えました。

ビデオがロードされていないため、開始前に黒い画面が表示されます。

ビデオの読み込みにかかる時間を予測することはできません。プレーヤーをviewWillApperメソッドに割り当てても。黒い画面が表示されます。この黒い画面はそれを制御できません。YouTube アプリやデフォルトの動画アプリも同様です。黒い画面の間、ActivityIndi​​cator または "Loading" メッセージがユーザーに表示されます。合理的です。最後に 一般的に、ビデオのサイズと品質が大きいほど、読み込みに時間がかかります。正確な読み込み時間が必要な場合は、通知する必要があります。

サンプルコードを参照してください。

- (void)viewWillAppear:(BOOL)animated
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"]];
    player = [[MPMoviePlayerController alloc] initWithContentURL:url];

    [player setControlStyle:MPMovieControlStyleNone];
    player.view.frame = CGRectMake(35, 190, 245, 156);
    [self.view addSubview:player.view];
    [player.view setBackgroundColor:[UIColor clearColor]];
    player.shouldAutoplay = NO;
    [player prepareToPlay];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadMoviePlayerStateChanged:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:self.player];

    [super viewWillAppear:animated];
}

- (void)loadMoviePlayerStateChanged:(NSNotification *)noti
{
    int loadState = self.player.loadState;
    if(loadState & MPMovieLoadStateUnknown)
    {
        NSLog(@"MPMovieLoadStateUnknown");
        return;
    }
    else if(loadState & MPMovieLoadStatePlayable)
    {
        NSLog(@"MPMovieLoadStatePlayable");
        [player play];
    }
    else if(loadState & MPMovieLoadStatePlaythroughOK)
    {
        NSLog(@"MPMovieLoadStatePlaythroughOK");
    } else if(loadState & MPMovieLoadStateStalled)
    {
        NSLog(@"MPMovieLoadStateStalled");
    }
}
于 2012-08-01T11:44:11.387 に答える