数组中的视频如何播放该视频。苹果手机

时间:2012-07-09 19:09:28

标签: iphone objective-c ios video

视频在阵列中。我想播放那些视频。

意味着服务器中有视频。视频也是一个阵列。我将该数组存储在字典中,如何播放视频

以下代码是对还是错,如果错误请告诉我正确的

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

1 个答案:

答案 0 :(得分: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];
 }