目前我使用以下代码获取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];
}
答案 0 :(得分: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];
}
答案 1 :(得分:2)
url是您的视频网址
MPMoviePlayerController *plyr =[[MPMoviePlayerController alloc] initWithContentURL: url];
[[plyr view] setFrame: [self.view bounds]];
[self.view addSubview: [plyr view]];
[plyr play];