gpt4 book ai didi

xcode - 如何从iphone库导入视频并在应用程序中播放

转载 作者:行者123 更新时间:2023-12-04 11:14:37 25 4
gpt4 key购买 nike

我正在使用以下代码来显示视频库

 -(IBAction)showVideoLibrary
{
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

videoPicker.mediaTypes =[[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie,nil];
if(self.popoverController!=nil)
{
[self.popoverController release];
}
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:videoPicker];
popoverController.delegate = self;
popoverController.popoverContentSize=CGSizeMake(320,1000);

[popoverController presentPopoverFromRect:CGRectMake(0,0,10,10) inView:self.view permittedArrowDirections:nil animated:YES];

}

并且为了接收选定的视频网址,我正在使用以下功能
- (void)imagePickerController: (UIImagePickerController *)picker2 didFinishPickingMediaWithInfo: (NSDictionary *)info {

NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:@"public.movie"])
{
NSLog(@"came to video select...");

NSURL *videoUrl=(NSURL*)[info objectForKey:@"UIImagePickerControllerMediaURL"];

NSLog(@"Got Movie Url==%@",videoUrl);


}

这是我正在使用的代码,我可以看到库中存在的视频列表,但是当我按下“使用”按钮时,它显示正在压缩视频..我无法取消它,而且我没有得到任何类型的网址在
- (void)imagePickerController: (UIImagePickerController *)picker2 didFinishPickingMediaWithInfo: (NSDictionary *)info

功能.. 解决这个问题的任何想法.. 并在应用程序中获取 url。

谢谢。

最佳答案

在真正的 iPhone 设备上试用

这是我在我的项目中使用的从 iPhone 库中挑选视频的代码

只需将选择器中的视频方法添加到您想要的按钮

  -(void)video
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;


imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];

[self presentModalViewController:imagePicker animated:YES];


}


-(void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info
{


NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo)
{

NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];

NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
// NSLog(@"%@",moviePath);

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}


[self dismissModalViewControllerAnimated:YES];

[picker release];


}

不要忘记添加移动核心服务框架

并导入
 #import <MobileCoreServices/UTCoreTypes.h>

字符串“moviepath”为您提供该 iPhone 中视频的路径,然后对该视频执行任何所需的操作。在字符串电影路径中完成压缩后,您将获得视频路径,“videourl”是该视频的 url 播放该视频
 MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url];   //  give here the "videourl"  
[[player view] setFrame: [self.view bounds]];
[self.view addSubview: [player view]];
[player play];

关于xcode - 如何从iphone库导入视频并在应用程序中播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6266681/

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