首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过iOS库获取视频文件路径:解决bug吗?

通过iOS库获取视频文件路径:解决bug吗?
EN

Stack Overflow用户
提问于 2020-07-25 15:19:32
回答 1查看 41关注 0票数 1

由于目前正在对一个iOS应用程序进行代码命名,因此该库不返回可用的视频文件路径,原因是存在以下错误:

https://github.com/codenameone/CodenameOne/issues/3181

以下可能解释了哪些原因:

didFinishPickingMediaWithInfo returns different URL in iOS 13

由于图库是我无法避免使用的基本关键特性,所以我尝试用临时的本机接口来解决这个问题,直到错误得到正确的修复为止。

我试图从这个答案中复制代码:https://stackoverflow.com/a/31355092/1277576

编写下列文件:

Gallery.java

代码语言:javascript
复制
package myapp.utilities;

import com.codename1.system.NativeLookup;

/**
 * Gallery
 */
public class Gallery {
    private static GalleryNative nativeInterface = NativeLookup.create(GalleryNative.class);
    
    public static String pickVideo() {
        if (nativeInterface != null && nativeInterface.isSupported()) {
            return nativeInterface.pickVideo();
        } else {
            return null;
        }
    }
} 

GalleryNative.java

代码语言:javascript
复制
package myapp.utilities;

import com.codename1.system.NativeInterface;

/**
 * @deprecated
 */
public interface GalleryNative extends NativeInterface {
    
    public String pickVideo();

} 

GalleryNativeImpl.h

代码语言:javascript
复制
#import <Foundation/Foundation.h>

@interface myapp_utilities_GalleryNativeImpl : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
}

-(NSString*)pickVideo;
-(BOOL)isSupported;
@end

GalleryNativeImpl.m

代码语言:javascript
复制
#import "myapp_utilities_GalleryNativeImpl.h"
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h> // needed for video types

@implementation app_aren_client_utilities_GalleryNativeImpl : UIViewController

-(NSString*)pickVideo{
    dispatch_sync(dispatch_get_main_queue(), ^{
        // Present videos from which to choose
        UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
        videoPicker.delegate = self; // ensure you set the delegate so when a video is chosen the right method can be called

        videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
        // This code ensures only videos are shown to the end user
        videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];

        videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
        [self presentViewController:videoPicker animated:YES completion:nil];
    });
    return nil;
}

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

    // This is the NSURL of the video object
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

    NSLog(@"VideoURL = %@", videoURL);
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:NULL];
}


-(BOOL)isSupported{
    return YES;
}

@end

但当我打电话给Gallery.pickVideo()时,我得到:

2020-07-25 16:38:08.401585+0200 MainClass[2731:207000] Warning: Attempt to present <UIImagePickerController: 0x107035800> on <app_aren_client_utilities_GalleryNativeImpl: 0x105f168d0> whose view is not in the window hierarchy! 2020-07-25 16:38:08.402068+0200 MainClass[2731:207198] [AXRuntimeCommon] Unknown client: MainClass

因此,我的问题是,我能做什么来获得视频文件路径的画廊(在一个代号为一个应用程序,当然)。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-26 02:04:29

你需要用这样的东西:

代码语言:javascript
复制
[[CodenameOne_GLViewController instance] presentViewController:activityViewController animated:YES completion:^{}];

如下图所示:https://github.com/codenameone/CodenameOne/blob/master/Ports/iOSPort/nativeSources/IOSNative.m#L7244

您还需要此导入:

代码语言:javascript
复制
#import "CodenameOne_GLViewController.h"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63090045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档