1

現在、NSURLを取得するために以下のコードを使用しています。しかし、NSURLを取得した後、どうすればそれを再生できますか?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
        {
            NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
            if ([mediaType isEqualToString:@"public.image"]){
                // UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
                UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
                NSLog(@"found an image");
            }
            else if ([mediaType isEqualToString:@"public.movie"]){
                NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
                NSLog([videoURL absoluteString]);
                NSLog(@"found a video");    
            }
            [picker dismissModalViewControllerAnimated:YES];
        }
4

2 に答える 2

4
- (void)selectVideoFromLibrary
{
   UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeMovie,
                                  nil];
        imagePicker.allowsEditing = NO;
        [self presentViewController:imagePicker animated:YES completion:nil];

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     NSURL *movieURL = (NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
     MPMoviePlayerController *movieplayer =[[MPMoviePlayerController alloc] initWithContentURL: url];    
    [[movieplayer view] setFrame: [self.view bounds]];  
    [self.view addSubview: [movieplayer view]];
    [movieplayer play];
}
于 2013-02-05T07:59:27.433 に答える
2

urlはあなたのビデオURLです

MPMoviePlayerController *plyr =[[MPMoviePlayerController alloc] initWithContentURL: url];    
[[plyr view] setFrame: [self.view bounds]];  
[self.view addSubview: [plyr view]];
[plyr play];
于 2012-12-12T11:31:42.753 に答える