陆续

2011-02-18 36 views
-1

在我的应用我要玩2个网址视频陆续播放从URL一个2个视频。陆续

这是我的代码:

` - (无效)viewDidLoad中{

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

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

[超级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在数组这样,

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

那我该怎么retrive的URL - (空)movieFinishedCallback:(NSNotification *)aNotification {

} method.please给予我指导这个。

回答

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]; 
} 
+0

@Harinder:如何网址存储在一个array.and我怎么能retrive URL的一个由one.please给我一个样品code.please保存我的生活。谢谢你 – kanmani 2011-02-18 10:06:37