0
現在我使用mpmovieplayercontroller,但我需要關閉mpmovieplayercontroller播放另一個視頻。 有沒有辦法在不關閉mpmovieplayercontroller的情況下播放多個視頻?,我怎麼能一個接一個地流幾個視頻?
THX
現在我使用mpmovieplayercontroller,但我需要關閉mpmovieplayercontroller播放另一個視頻。 有沒有辦法在不關閉mpmovieplayercontroller的情況下播放多個視頻?,我怎麼能一個接一個地流幾個視頻?
THX
您可以訂閱你的MPMoviePlayerController
的MPMoviePlayerPlaybackDidFinishNotification
通知。
例如,您有:
// 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];
}
}