一个接一个地从网址播放2个视频

时间:2011-02-18 09:40:24

标签: iphone url video mpmovieplayercontroller

在我的应用程序中,我想一个接一个地播放2个网址视频。

这是我的代码:

` - (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];   

}

`

在完成一个网址视频后,我想播放下一个网址视频。

请有人帮助我。

我将网址存储在这个数组中,

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

然后我怎样才能在 - (void)movieFinishedCallback :( NSNotification *)aNotification {

中检索网址

} method.please给我指导。

1 个答案:

答案 0 :(得分:1)

我还没有测试过,但应该可以使用,你可能需要它稍微修改一下。至少,你现在有了一个想法,如何做到这一点

-(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];
 }