gpt4 book ai didi

iphone - 如何从相册中获取视频并播放

转载 作者:行者123 更新时间:2023-11-29 04:43:24 27 4
gpt4 key购买 nike

请帮我举一个从相册中获取视频并播放的示例。

以下代码不起作用

NSURL *URL = [info objectForKey:UIImagePickerControllerMediaURL];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:aurl];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.useApplicationAudioSession = NO;
moviePlayerController.fullscreen = YES;
[moviePlayerController play];

最佳答案

 // Choose video from library                   
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
imagePicker.sourceType];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];

//获取视频

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
NSLog(@"found an image");
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"found a video");
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
}

}

//播放视频

MPMoviePlayerViewController *movie = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self.view addSubview:movie.view];
[self presentMoviePlayerViewControllerAnimated:movie];
[movie release];

关于iphone - 如何从相册中获取视频并播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10023939/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com