在iphone上从url播放一个视频时调用另一个URL

时间:2011-02-23 12:01:37

标签: iphone url video mpmovieplayercontroller

在我的应用程序中,我一个接一个地从阵列播放2个视频。我想在第一个视频开始播放时点击另一个网址而不影响视频播放。

以下是我的代码,我试图一个接一个地播放两个视频,

-(IBAction)playMovie:(id)sender{    
i=0;
array=[[NSArray alloc] initWithObjects:@"https://s3.amazonaws.com/adplayer/colgate.mp4",@"https://s3.amazonaws.com/ventuno-platform-flv-sep2010/happy_family.mp4",nil];
[self initializPlayer]; }

当用户点击按钮开始播放视频时,会调用上述操作事件。

-(void)initializPlayer{

if(i<[array count])     

    i +=1;
else {
    i = 1;
}

NSLog(@"i value:%@",[array objectAtIndex:i-1]);
NSURL *url1=[NSURL URLWithString:[array objectAtIndex:i-1]];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url1];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlaybackComplete:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayerController];

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayerPlaybackStateDidChange:) 
                                             name:MPMoviePlayerPlaybackStateDidChangeNotification 
                                           object:moviePlayerController];

[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen=YES;
[moviePlayerController play];}

在initializPlayer方法中,两个视频一个接一个地播放,还有两个通知,第一个用于通知视频完成时或用户按下完成按钮。另一个用于通知,

1.videoplay 2.videopause 3.video中断 4.videoforward 5.videobackward

 -(void)moviePlaybackComplete:(NSNotification *)notification{

NSLog(@"moviePlaybackComplete");
MPMoviePlayerController *moviePlayerController=[notification object];

[[NSNotificationCenter defaultCenter] removeObserver:self 
            name:MPMoviePlayerPlaybackDidFinishNotification 
            object:moviePlayerController];

[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
[self initializPlayer];}

moviePlaybackComplete通知用于在视频完成时通知用户。

-(void) moviePlayerPlaybackStateDidChange:(NSNotification*)notification {

NSLog(@"moviePlayerPlaybackStateDidChange");
MPMoviePlayerController *moviePlayer = notification.object;
MPMoviePlaybackState playbackState = moviePlayer.playbackState;
if(playbackState == MPMoviePlaybackStateStopped)
{
    //NSLog(@"MPMoviePlaybackStateStopped");
} 
if(playbackState == MPMoviePlaybackStatePlaying) 
{
    //NSLog(@"MPMoviePlaybackStatePlaying");
} 
if(playbackState == MPMoviePlaybackStatePaused)
{
    //NSLog(@"MPMoviePlaybackStatePaused");
} 
if(playbackState == MPMoviePlaybackStateInterrupted) 
{
    NSLog(@"MPMoviePlaybackStateInterrupted");
} 
if(playbackState == MPMoviePlaybackStateSeekingForward)
{
    NSLog(@"MPMoviePlaybackStateSeekingForward");
} 
if(playbackState == MPMoviePlaybackStateSeekingBackward)
{
    NSLog(@"MPMoviePlaybackStateSeekingBackward********");
}}

moviePlayerPlaybackStateDidChange通知用于通知用户是否在回放状态中进行了任何更改。

MY DOUBT:

在第一次视频播放(开始)时,我想在不影响视频的情况下点击另一个网址。在第一个视频结尾处再添加一个网址。

请指导我这样做。

谢谢

0 个答案:

没有答案