iPhone - 选择视频...带有两个栏的 URL?

发布于 2024-10-09 01:10:59 字数 1987 浏览 0 评论 0原文

我有一个 UIPickerController 可以在我的应用程序中选择视频,但使用选择器选择视频时它会崩溃。当我直接向 MPMoviePlayerController 提供 URL 时,它工作正常,但是当 URL 来自 UIPickerController 时,它会正确加载影片,但在创建缩略图时会崩溃。

我已将 URL 转储到控制台,就在选择文件之后,这就是我看到的

file://localhost/private/var/mobile/Applications/FA667F85-B009-46FA-A0B9-A7345A072651/tmp//trim.Ir0gqx.MOV

第一个问题:为什么文件名之前有双杠? 第二个问题:如果我在选择器上编辑“否”,为什么文件名带有修剪前缀?

这是选择器代码:

- (void) selectMovie:(id) sender {

    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

        picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
        picker.delegate = self;
        picker.allowsEditing = NO;
        picker.videoQuality = UIImagePickerControllerQualityTypeHigh; // I've added this trying to make it stop compressing the video, but it won't... any clues?


        UIPopoverController *aPopover = 
            [[UIPopoverController alloc] initWithContentViewController:picker];

        aPopover.delegate = self;


        CGRect myRect = [sender frame];

        [aPopover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

    }   
}



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

{
    NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];  

    if ( [ mediaType isEqualToString:@"public.movie" ]){
            movieURL =  [info objectForKey:UIImagePickerControllerMediaURL];
    } 

    NSLog(@"%@", movieURL);

    [self loadMovie:movieURL];

}

I have a UIPickerController to select videos in my App and it is crashing when selecting videos using the picker. When I feed the MPMoviePlayerController with the URL directly it works fine, but when the URL comes from the UIPickerController, it loads the movie correctly but crashes when the thumbnails are being created.

I have dumped the URL to the console, just after the file is selected and this is what I see

file://localhost/private/var/mobile/Applications/FA667F85-B009-46FA-A0B9-A7345A072651/tmp//trim.Ir0gqx.MOV

first question: why is the double bar before the file name?
second question: why the file name comes with a trim prefix if I have editing NO on the picker?

this is the picker code:

- (void) selectMovie:(id) sender {

    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

        picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
        picker.delegate = self;
        picker.allowsEditing = NO;
        picker.videoQuality = UIImagePickerControllerQualityTypeHigh; // I've added this trying to make it stop compressing the video, but it won't... any clues?


        UIPopoverController *aPopover = 
            [[UIPopoverController alloc] initWithContentViewController:picker];

        aPopover.delegate = self;


        CGRect myRect = [sender frame];

        [aPopover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

    }   
}



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

{
    NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];  

    if ( [ mediaType isEqualToString:@"public.movie" ]){
            movieURL =  [info objectForKey:UIImagePickerControllerMediaURL];
    } 

    NSLog(@"%@", movieURL);

    [self loadMovie:movieURL];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宣告ˉ结束 2024-10-16 01:10:59

我的想法是您的应用程序没有权限在电影存储的位置生成缩略图。尝试将电影文件从相册复制到文档目录中:

NSFileManager *fm = [NSFileManager defaultManager];
[fm moveItemAtURL:fromURL toURL:toURL error:&error];

假设您有一个 toURL 指向文档目录中的文件名。

My thought is that your app does not have permission to generate thumbnails in the location where the movie is stored. Try copying the movie file out of the photo albums and into your documents directory:

NSFileManager *fm = [NSFileManager defaultManager];
[fm moveItemAtURL:fromURL toURL:toURL error:&error];

Assuming you have a toURL pointing to a filename in your docs directory.

挽梦忆笙歌 2024-10-16 01:10:59

我只知道第一个,因为你需要向 MPMoviePlayerController 提供一个 url,一个 url 必须以一个方案开头,http://, smtp:// 之类的。 file:// 也是文件 url 的方案

I only know about the first one, because you need to feed to MPMoviePlayerController a url, a url has to start with a scheme, http://, smtp://, kind of that. file:// is also a scheme for file url

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文