0

現在、mpmovieplayercontroller を使用していますが、別のビデオを再生するには mpmovieplayercontroller を閉じる必要があります。mpmovieplayercontroller を閉じずに複数のビデオを再生する方法はありますか?

どうも

4

1 に答える 1

3

MPMoviePlayerControllerMPMoviePlayerPlaybackDidFinishNotification通知を購読できます。

たとえば、次のようなものがあります。

// this is a PoC code, you can do it a lot cleaner
// in your .h
@property (nonatomic, retain) MPMoviePlayerController *moviePlayer;
@property (nonatomic, retain) NSMutableArray *movieUrls; 
int indexPlayed;

// in your .m
- (void)setupPlayer { // or in your constructor, viewDidLoad, etc
    moviePlayer = [[MPMoviePlayer alloc] init];
    movieUrls = [NSMutableArray arrayWithObjects:nil, nil, nil]; // add your movie NSURLs here
    indexPlayed = 0;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlay:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
    [self playerPlay:nil];
}
- (void)playerPlay:(NSNotification *)n {
    if (indexPlayed < [movieUrls count]) {
        moviePlayer.contentURL = [movieUrls objectAtIndex:indexPlayed++];
        [moviePlayer play];
    }
}
于 2009-11-05T16:49:22.797 に答える