title: play all videos from gallery ios
body: <p>i want to play all videos from gallery directly, but in this code last video is played every time, what should i do to play all videos in a sequence one by one</p>
  
  <pre><code> ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
  
      [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
          if (group) {
              [group setAssetsFilter:[ALAssetsFilter allVideos]];
              [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
  
                  if (asset)
                  {
  
                      NSDictionary *meta = [[asset defaultRepresentation] metadata];
  
                      if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
                          // asset is a video
                          NSLog(@"See Asset: %@", asset);
  
                          self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[[asset defaultRepresentation] url]];
                          if (self.moviePlayer != nil)
                          {
                              [self stopPlayingVideo:nil];
                          }
                          if (self.moviePlayer != nil)
                          {
                              [[NSNotificationCenter defaultCenter]
                               addObserver:self
                               selector:@selector(videoHasFinishedPlaying:)
                               name:MPMoviePlayerPlaybackDidFinishNotification
                               object:self.moviePlayer];
                              NSLog(@"Successfully instantiated the movie player.");
                              /* Scale the movie player to fit the aspect ratio */
                              self.moviePlayer.scalingMode = MPMovieScalingModeNone;
                              /* Let's start playing the video in full screen mode */
                              self.moviePlayer.view.frame = CGRectMake(100, 50, 650, 500);
                              [self.moviePlayer play];
                              //        [self.moviePlayer.view setFrame:self.view.bounds];
                              [self.view addSubview:self.moviePlayer.view];
                              [self.moviePlayer setFullscreen:NO
                                                     animated:YES];
  
                              volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(-410, 300, 140, 52)] ;
  
                              [self.view addSubview:volumeView];
  
  
                              CGAffineTransform trans = CGAffineTransformMakeRotation(M_PI_2);
                              volumeView.transform = trans;
  
  
                              for (id current in volumeView.subviews) {
                                  if ([current isKindOfClass:[UISlider class]]) {
                                      volumeSlider = (UISlider *)current;
  
                                      volumeSlider.minimumTrackTintColor = [UIColor grayColor];
                                      volumeSlider.maximumTrackTintColor = [UIColor whiteColor];
  
  
                                      volumeSlider.value = volumeSlider.maximumValue;
                                      [btnVol setBackgroundImage:[UIImage imageNamed:@"mx_vol.png"] forState:UIControlStateNormal];
  
                                  }
                              }
  
  
                              [self.moviePlayer setControlStyle:MPMovieControlStyleNone];
                          } else {
                              NSLog(@"Failed to instantiate the movie player.");
                          }
                          [_moviePlayer setRepeatMode:MPMovieRepeatModeOne];
  
                      }
  
                      //                    NSLog(@"%@",asset);
                                          NSLog(@"%@",meta);
  
                  }
              }];
          }
      } failureBlock:^(NSError *error) {
          NSLog(@"error enumerating AssetLibrary groups %@\n", error);
      }];
  </code></pre>