2012-07-09 83 views
-1

視頻在陣列中。我想播放那些視頻。視頻在陣列中如何播放該視頻。 iphone

意味着視頻在服務器中。視頻進入陣列。我存儲在陣列IA字典從字典如何播放視頻

是下面的代碼是對還是錯的,如果它錯了,請告訴我正確的

enter code here NSMutableDictionary *dict; 


dict =[Videoarray objectAtIndex:0]; 
NSURL *Movie = [[NSURL alloc] initWithString:[dict valueForKey:@"url"]]; 
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:Movie]; 
theMovie.scalingMode = MPMovieScalingModeAspectFill; 
[theMovie play]; 
MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:Movie]; 
movie.view.frame = CGRectMake(5,5,310, 165); 
movie.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | 
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 
[scroll addSubview:movie.view]; 
[movie play]; 
+0

您是否試過該代碼?什麼不起作用? – woz 2012-07-09 19:14:11

+0

只有一個視頻即將到來,但在陣列中,所以可能有視頻如何檢索所有視頻。在iPhone – 2012-07-09 19:16:13

+0

你希望他們連續播放,對嗎? – woz 2012-07-09 19:24:55

回答

2

這是非常粗略的代碼打數組連續播放視頻:

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

-(void)setUpPlayer { 
    if(i <= [videoArray count]) { 
     player = [[MPMoviePlayerController alloc] initWithContentURL:[videoArray objectAtIndex:i]]; 
     i++; //use a static integer outside these functions as an index 
     [NSNotificationCenter defaultCenter]addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; 
     [player play]; 
    } 
} 


- (void) movieFinishedCallback:(NSNotification*) aNotification { 
    player = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];  
    [self setUpPlayer]; 
}