2014-06-17 3 views
0

갤러리에서 직접 비디오를 재생하고 싶습니다.이 코드는 이미지와 비디오 URL을 모두 얻을 수 있지만 자동으로 비디오를 재생할 수 없습니다. 코드 또는 도움을 주시면 감사하겠습니다. 초기화 및 계층 구조에 뷰의 추가, 그리고 같은 것을비디오를 갤러리에서 직접 다운로드

#import <MediaPlayer/MediaPlayer.h> 

@interface MyViewController() 
@property (strong, nonatomic) MPMoviePlayerController *mp; 
@end 

:

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




        } 

//     NSLog(@"%@",asset); 
//     NSLog(@"%@",meta); 

       } 
      }]; 
     } 
    } failureBlock:^(NSError *error) { 
     NSLog(@"error enumerating AssetLibrary groups %@\n", error); 
    }]; 
+0

제공된 코드가 비디오 재생과 관련없는 것 같습니다. – danh

+0

수정 됨 그것을 확인하시기 바랍니다. – NullData

+0

아직 볼 수 없습니다. 저작물 URL을 얻은 후에는 MPMoviePlayer로 재생하여 contentURL을 제공 할 수 있어야합니다. – danh

답변

0

당신이 비디오를보고 싶어 뷰 컨트롤러에서 다음 프로젝트의 MediaPlayer를 프레임 워크를 포함 :

- (void)playUrl:(NSURL *)contentURL { 

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:contentURL]; 
    player.view.frame = // some CGRect here that fits your view 

    [player prepareToPlay]; 
    [self.view addSubview:player.view]; 
    self.mp = player; 
} 
+0

에서 내 영화 URL을 볼 수 없습니다. 내 질문을받지 못했습니다. – NullData

관련 문제