陸續

2011-02-18 40 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