Воспроизвести 2 видео с URL один за другим - PullRequest
0 голосов
/ 18 февраля 2011

В моем приложении я хочу воспроизводить 2 видео по URL один за другим.

Это мой код:

`- (void) viewDidLoad {

NSLog(@"viewDidLoad");
player = [[MPMoviePlayerController alloc] initWithContentURL:[self movieURL]];

[NSNotificationCenter defaultCenter]addObserver:self 
                                        selector:@selector(movieFinishedCallback:)
                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:player];
[player play];

[super vieDidLoad];}

- (NSURL *)movieURL {

return [NSURL URLWithString: @"https://s3.amazonaws.com/adplayer/colgate.mp4"];//First video url after this video complete.I want to play the next url video.

}

- (void) movieFinishedCallback:(NSNotification*) aNotification {

NSLog(@"movieFinishedCallback");
player = [aNotification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];    
[player autorelease];   

}

`

После завершения одного видео URL я хочу воспроизвести следующее видео URL.

пожалуйста, кто-нибудь, помогите мне.

Я храню URL в массиве, как это,

array=[[NSArray alloc] initWithObjects:@"https://s3.amazonaws.com/adplayer/colgate.mp4",@"https://s3.amazonaws.com/ventuno-platform-flv-sep2010/happy_family.mp4",nil];

Тогда как я могу получить URL в - (void) movieFinishedCallback: (NSNotification*) Способ уведомления {

}. Пожалуйста, дайте мне руководство в этом.

1 Ответ

1 голос
/ 18 февраля 2011

Я не тестировал его, но он должен работать, возможно, вам придется немного его изменить.По крайней мере, теперь у вас есть идея, как это можно сделать

-(void)viewDidLoad
{ 
     [self initializPlayer];
}



static int i;   
-(void)initializPlayer
{
    if(i<=[arrMovieURL count])
        i +=1;
    else {
        i = 0;
    }

    if(player)
    {
        [player release];
        player = nil;
    }
    player = [[MPMoviePlayerController alloc] initWithContentURL:[arrMovieURL objectAtIndex:i]];

    [NSNotificationCenter defaultCenter]addObserver:self 
    selector:@selector(movieFinishedCallback:)
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:player];

    [player play];
}


- (void) movieFinishedCallback:(NSNotification*) aNotification {

NSLog(@"movieFinishedCallback");
player = [aNotification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];    

 //calling again to play the next video
  [self initializPlayer];
 }
...