adds support for video files
This commit is contained in:
parent
cf8ceb57da
commit
2826379e15
|
@ -136,6 +136,8 @@ public class FilePickerPlugin implements MethodCallHandler {
|
||||||
switch (type){
|
switch (type){
|
||||||
case "PDF":
|
case "PDF":
|
||||||
return "application/pdf";
|
return "application/pdf";
|
||||||
|
case "VIDEO":
|
||||||
|
return "video/*";
|
||||||
case "ANY":
|
case "ANY":
|
||||||
return "*/*";
|
return "*/*";
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -29,12 +29,6 @@ class _MyAppState extends State<MyApp> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Platform messages are asynchronous, so we initialize in an async method.
|
|
||||||
|
|
||||||
// If the widget was removed from the tree while the asynchronous platform
|
|
||||||
// message was in flight, we want to discard the reply rather than calling
|
|
||||||
// setState to update our non-existent appearance.
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new MaterialApp(
|
return new MaterialApp(
|
||||||
|
@ -64,15 +58,21 @@ class _MyAppState extends State<MyApp> {
|
||||||
child: new Text('FROM PDF'),
|
child: new Text('FROM PDF'),
|
||||||
value: FileType.PDF,
|
value: FileType.PDF,
|
||||||
),
|
),
|
||||||
|
new DropdownMenuItem(
|
||||||
|
child: new Text('VIDEO'),
|
||||||
|
value: FileType.VIDEO,
|
||||||
|
),
|
||||||
new DropdownMenuItem(
|
new DropdownMenuItem(
|
||||||
child: new Text('ANY'),
|
child: new Text('ANY'),
|
||||||
value: FileType.ANY,
|
value: FileType.ANY,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(
|
||||||
_pickingType = value;
|
() {
|
||||||
});
|
_pickingType = value;
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#import <Flutter/Flutter.h>
|
#import <Flutter/Flutter.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <MobileCoreServices/MobileCoreServices.h>
|
||||||
|
|
||||||
@interface FilePickerPlugin : NSObject<FlutterPlugin, UIDocumentPickerDelegate>
|
@interface FilePickerPlugin : NSObject<FlutterPlugin, UIDocumentPickerDelegate, UITabBarDelegate, UINavigationControllerDelegate,UIImagePickerControllerDelegate>
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#import "FilePickerPlugin.h"
|
#import "FilePickerPlugin.h"
|
||||||
|
#import "FileUtils.h"
|
||||||
|
|
||||||
@interface FilePickerPlugin()
|
@interface FilePickerPlugin()
|
||||||
@property (nonatomic) FlutterResult result;
|
@property (nonatomic) FlutterResult result;
|
||||||
|
@ -24,30 +25,18 @@
|
||||||
|
|
||||||
- (instancetype)initWithViewController:(UIViewController *)viewController {
|
- (instancetype)initWithViewController:(UIViewController *)viewController {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if(self){
|
if(self) {
|
||||||
self.viewController = viewController;
|
self.viewController = viewController;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) resolveType:(NSString*)type {
|
|
||||||
|
|
||||||
if ([type isEqualToString:@"PDF"]) {
|
|
||||||
return @"com.adobe.pdf";
|
|
||||||
}
|
|
||||||
else if ([type isEqualToString:@"ANY"]) {
|
|
||||||
return @"public.item";
|
|
||||||
} else {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)initPicker {
|
- (void)initPicker {
|
||||||
|
|
||||||
self.pickerController = [[UIDocumentPickerViewController alloc]
|
self.pickerController = [[UIDocumentPickerViewController alloc]
|
||||||
initWithDocumentTypes:@[self.fileType]
|
initWithDocumentTypes:@[self.fileType]
|
||||||
inMode:UIDocumentPickerModeImport];
|
inMode:UIDocumentPickerModeImport];
|
||||||
|
|
||||||
self.pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
self.pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
||||||
self.pickerController.delegate = self;
|
self.pickerController.delegate = self;
|
||||||
|
@ -61,20 +50,26 @@
|
||||||
_result = nil;
|
_result = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fileType = [self resolveType:call.method];
|
_result = result;
|
||||||
|
|
||||||
if(self.fileType == nil){
|
|
||||||
result(FlutterMethodNotImplemented);
|
if([call.method isEqualToString:@"VIDEO"]) {
|
||||||
} else {
|
[self resolvePickVideo];
|
||||||
|
}
|
||||||
[self initPicker];
|
else {
|
||||||
_result = result;
|
self.fileType = [FileUtils resolveType:call.method];
|
||||||
[_viewController presentViewController:self.pickerController animated:YES completion:^{
|
|
||||||
if (@available(iOS 11.0, *)) {
|
|
||||||
self.pickerController.allowsMultipleSelection = NO;
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
if(self.fileType == nil){
|
||||||
|
result(FlutterMethodNotImplemented);
|
||||||
|
} else {
|
||||||
|
[self initPicker];
|
||||||
|
[_viewController presentViewController:self.pickerController animated:YES completion:^{
|
||||||
|
if (@available(iOS 11.0, *)) {
|
||||||
|
self.pickerController.allowsMultipleSelection = NO;
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -83,35 +78,32 @@
|
||||||
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
|
||||||
|
|
||||||
[self.pickerController dismissViewControllerAnimated:YES completion:nil];
|
[self.pickerController dismissViewControllerAnimated:YES completion:nil];
|
||||||
|
_result([FileUtils resolvePath:urls]);
|
||||||
NSString * uri;
|
|
||||||
|
|
||||||
for (NSURL *url in urls) {
|
|
||||||
uri = (NSString *)[url path];
|
|
||||||
}
|
|
||||||
|
|
||||||
_result(uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentInteractionController delegate
|
|
||||||
|
|
||||||
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
|
// VideoPicker delegate
|
||||||
_result(@"Finished");
|
|
||||||
}
|
|
||||||
|
|
||||||
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
|
- (void) resolvePickVideo{
|
||||||
NSLog(@"Finished");
|
|
||||||
return _viewController;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
|
|
||||||
|
|
||||||
NSLog(@"Starting to send this puppy to %@", application);
|
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
|
||||||
|
videoPicker.delegate = self;
|
||||||
|
videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
|
||||||
|
videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];
|
||||||
|
videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
|
||||||
|
|
||||||
|
[self.viewController presentViewController:videoPicker animated:YES completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application {
|
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
|
||||||
|
|
||||||
NSLog(@"We're done sending the document.");
|
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
|
||||||
|
[picker dismissViewControllerAnimated:YES completion:NULL];
|
||||||
|
_result([videoURL path]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
||||||
|
[picker dismissViewControllerAnimated:YES completion:NULL];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
//
|
||||||
|
// FileUtils.h
|
||||||
|
// Pods
|
||||||
|
//
|
||||||
|
// Created by Miguel Ruivo on 05/12/2018.
|
||||||
|
//
|
||||||
|
@interface FileUtils : NSObject
|
||||||
|
+ (NSString*) resolveType:(NSString*)type;
|
||||||
|
+ (NSString*) resolvePath:(NSArray<NSURL *> *)urls;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
//
|
||||||
|
// FileUtils.m
|
||||||
|
// file_picker
|
||||||
|
//
|
||||||
|
// Created by Miguel Ruivo on 05/12/2018.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "FileUtils.h"
|
||||||
|
|
||||||
|
@implementation FileUtils
|
||||||
|
|
||||||
|
+ (NSString*) resolveType:(NSString*)type {
|
||||||
|
|
||||||
|
if ([type isEqualToString:@"PDF"]) {
|
||||||
|
return @"com.adobe.pdf";
|
||||||
|
}
|
||||||
|
else if ([type isEqualToString:@"ANY"]) {
|
||||||
|
return @"public.item";
|
||||||
|
} else {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
+ (NSString*) resolvePath:(NSArray<NSURL *> *)urls{
|
||||||
|
NSString * uri;
|
||||||
|
|
||||||
|
for (NSURL *url in urls) {
|
||||||
|
uri = (NSString *)[url path];
|
||||||
|
}
|
||||||
|
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -7,6 +7,7 @@ enum FileType {
|
||||||
ANY,
|
ANY,
|
||||||
PDF,
|
PDF,
|
||||||
IMAGE,
|
IMAGE,
|
||||||
|
VIDEO,
|
||||||
CAPTURE,
|
CAPTURE,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,12 +24,14 @@ class FilePicker {
|
||||||
|
|
||||||
static Future<String> getFilePath({FileType type = FileType.ANY}) async {
|
static Future<String> getFilePath({FileType type = FileType.ANY}) async {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case FileType.PDF:
|
|
||||||
return _getPath('PDF');
|
|
||||||
case FileType.IMAGE:
|
case FileType.IMAGE:
|
||||||
return _getImage(ImageSource.gallery);
|
return _getImage(ImageSource.gallery);
|
||||||
case FileType.CAPTURE:
|
case FileType.CAPTURE:
|
||||||
return _getImage(ImageSource.camera);
|
return _getImage(ImageSource.camera);
|
||||||
|
case FileType.PDF:
|
||||||
|
return _getPath('PDF');
|
||||||
|
case FileType.VIDEO:
|
||||||
|
return _getPath('VIDEO');
|
||||||
default:
|
default:
|
||||||
return _getPath('ANY');
|
return _getPath('ANY');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue