Воспроизведение видео, сохраненного в Camera Roll - PullRequest
1 голос
/ 24 января 2012

Мое приложение для iphone может сохранять фотографии и видео в Фотопленке, и я также смог получить доступ к элементам в фотопленке.

Отображать фотографии из фотопленки было легко, я сделал это с помощью ALAssetsLibraryи это прекрасно показывает в UIImage.Я тоже могу получить доступ к видео и попытался отобразить видео с помощью MPMoviePlayerController.

Вот мой код:

ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];

    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
    [assetLibrary   enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos 
                    usingBlock:^(ALAssetsGroup *group, BOOL *stop){
                        // Within the group enumeration block, filter to enumerate just videos.
                        [group setAssetsFilter:[ALAssetsFilter allVideos]];

                          // Chooses the video at the last index
                          [group  enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets]-1)] 
                                                   options:0
                                                usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop){   
                                                    if (alAsset){
                                                        ALAssetRepresentation *representation = [alAsset defaultRepresentation];
                                                        MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: [representation url]];
                                                        [moviePlayer.view setFrame:CGRectMake(20, 20, 200, 300)];
                                                        [self.view addSubview: moviePlayer.view];
                                                        [moviePlayer prepareToPlay];
                                                        [moviePlayer play];
                                                    }
                                                }
                           ];
                      }
                    failureBlock: ^(NSError *error){
                        // handle error
                        NSLog(@"No groups");
                    }
     ];

Я вижу только черную рамку, но не видео.

Кто-нибудь может мне помочь?

Спасибо.

Ответы [ 2 ]

0 голосов
/ 09 июня 2015

Попробуй это. Я пишу это для CollectionViewCell, вы можете обновить moviePlayerController.view.frame, как вы хотите.

MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[[asset defaultRepresentation] url]];
        moviePlayerController.view.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);//self.view.frame;
        moviePlayerController.movieSourceType= MPMovieSourceTypeFile;
        moviePlayerController.fullscreen = YES;
        [self.view addSubview:moviePlayerController.view];
        [moviePlayerController play];
0 голосов
/ 24 января 2012

Посмотрите на MPMoviePlayerViewController:

MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:[representation url]];
[self presentMoviePlayerViewControllerAnimated:player];
[player.moviePlayer play];
[player release];

Документы: http://developer.apple.com/library/ios/documentation/mediaplayer/reference/mpmovieplayerviewcontroller_class/Reference/Reference.html#//apple_ref/occ/instp/MPMoviePlayerViewController

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...