Commit 23f700a2 authored by 林生雨's avatar 林生雨

commit

parent a2d54ab0
This diff is collapsed.
......@@ -96,12 +96,11 @@ class AlbumModel {
// }
// });
// }
compute(paseAlbum, event).then((value){
compute(paseAlbum, event).then((value) {
_mainValue = value;
albumLive.notifyView(_mainValue[_nowDirName]);
});
// _mainValue=newMap;
// var list = map[_nowDirName];
// _mainValue.forEach((k, itemList) {
......@@ -133,7 +132,6 @@ class AlbumModel {
// }
// }
// print("EVENTTTT !! ${tempList.length} ${tempList}");
}
void _onError(Object error) {
......@@ -146,8 +144,7 @@ class AlbumModel {
.receiveBroadcastStream()
.listen(_onEvent, onError: _onError);
// }
AlbumRepository.getInstance().scanPhoneImg()
.listen((value) {
AlbumRepository.getInstance().scanPhoneImg().listen((value) {
if (value != null) {
_mainValue = value;
value.forEach((key, eachValue) {
......@@ -347,26 +344,32 @@ class AlbumModel {
showPop = false;
albumLive.notifyView(_mainValue[dirName]);
}
bool previewItemClick = false;
void previewItem(BuildContext context, int index, String pageName) {
String path;
if (Platform.isAndroid) {
path = albumLive.data[index].realPath;
Navigator.push(context, CustomRoute(AlbumPreviewPage(path, pageName)));
} else {
path = albumLive.data[index].path;
if (albumLive.data[index].isVideo) {
GengmeiFlutterPlugin.playAlbumVideo(path);
} else {
if (previewItemClick) {
return;
}
previewItemClick = true;
iosItem(path, context, (value) {
var realPath = value["realImagePath"];
Navigator.push(
context, CustomRoute(AlbumPreviewPage(realPath, pageName)));
});
}
// Navigator.push(
// context, CustomRoute(AlbumPreviewPage(albumLive.data[index].path, pageName)));
if (previewItemClick) {
return;
}
previewItemClick = true;
path = albumLive.data[index].path;
iosItem(path, context, (value) {
var realPath = value["realImagePath"];
Navigator.push(
context, CustomRoute(AlbumPreviewPage(realPath, pageName)));
});
}
}
......@@ -375,9 +378,9 @@ class AlbumModel {
if (value != null) {
fun(Map<String, String>.from(value));
}
previewItemClick=false;
previewItemClick = false;
}).catchError((error) {
previewItemClick=false;
previewItemClick = false;
print(error);
});
}
......
......@@ -4,6 +4,8 @@
#import "Image/AlbumItem.h"
#import "ResultManager.h"
#import <ImageIO/ImageIO.h>
#import <AVKit/AVKit.h>
#import "MyPlayerViewController.h"
@interface GengmeiFlutterPlugin () <UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,FlutterStreamHandler> //一定要声明这三个协议,缺一不可
//@property(nonatomic)FlutterResult result;
......@@ -408,6 +410,28 @@ NSString *cacheDirectory;
}else{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :nil];
}
}else if([@"play_album_video" isEqualToString:call.method] ){
long resultTemp=self.resultKey;
NSString * path=call.arguments;
if([[self.scanMap allKeys] containsObject:path]){
PHAsset * assets=self.scanMap[path];
MyPlayerViewController* video=[[MyPlayerViewController alloc] init];
[viewController presentViewController:video animated:YES completion:nil];
// video.player= [[AVPlayeralloc]initWithURL:url];
[video playMovie:assets];
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :@YES];
// PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
// options.version = PHImageRequestOptionsVersionCurrent;
// options.networkAccessAllowed = true;
// options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
// [[PHImageManager defaultManager]requestAVAssetForVideo:assets options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
// AVURLAsset *urlAsset = (AVURLAsset *)asset;
// AVPlayerViewController* video=[[AVPlayerViewController alloc] init];
// [viewController presentViewController:video animated:YES completion:nil];
// [video playMovie:urlAsset.URL];
// [[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :@YES];
// }];
}
}else{
result(FlutterMethodNotImplemented);
}
......
//
// AVPlayerViewController.h
// Pods
//
// Created by Apple on 2019/11/1.
//
#ifndef AVPlayerViewController_h
#define AVPlayerViewController_h
#endif /* AVPlayerViewController_h */
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>
@interface MyPlayerViewController : UIViewController
- (void)playMovie:(PHAsset*) assets;
@end
//
// AVPlayerViewController.m
// gengmei_flutter_plugin
//
// Created by Apple on 2019/11/1.
//
#import <Foundation/Foundation.h>
#import "MyPlayerViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>
@interface MyPlayerViewController()
@property(nonatomic)dispatch_queue_t queue;;
@end
@implementation MyPlayerViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.queue = dispatch_queue_create("com.gengmei_flutter_plugin", DISPATCH_QUEUE_SERIAL);
// UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
// button.frame = CGRectMake(100, 100, 100, 100);
// [button setTitle:@"TICK" forState:UIControlStateNormal];
// button.backgroundColor = [UIColor brownColor];
// [button addTarget:self action:@selector(playMovie) forControlEvents:UIControlEventTouchUpInside];
// [self.view addSubview:button];
}
- (void)playMovie:(PHAsset*) assets{
dispatch_async(self.queue, ^{
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
// options.version = PHImageRequestOptionsVersionCurrent;
options.networkAccessAllowed = true;
// options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
[[PHImageManager defaultManager]requestAVAssetForVideo:assets options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
dispatch_async(dispatch_get_main_queue(), ^{
AVURLAsset *urlAsset = (AVURLAsset *)asset;
// AVPlayerViewController* video=[[AVPlayerViewController alloc] init];
// [viewController presentViewController:video animated:YES completion:nil];
// [video playMovie:urlAsset.URL];
AVPlayer *player = [AVPlayer playerWithURL:urlAsset.URL];
// 2.创建视频播放视图的控制器
AVPlayerViewController *playerVC = [[AVPlayerViewController alloc]init];
playerVC.player = player;
playerVC.entersFullScreenWhenPlaybackBegins = YES;
playerVC.exitsFullScreenWhenPlaybackEnds = YES;
playerVC.videoGravity = AVLayerVideoGravityResizeAspect;
playerVC.view.center = self.view.center;
playerVC.view.frame = self.view.bounds;
playerVC.showsPlaybackControls = YES;
playerVC.view.translatesAutoresizingMaskIntoConstraints = YES;
// 隐藏 控制控件
// playerVC.showsPlaybackControls = NO;
// [self presentViewController:playerVC animated:YES completion:nil];
// 自定义位置
// playerVC.view.frame = CGRectMake(200, 300, 300, 300);
[self.view addSubview:playerVC.view];
[self addChildViewController:playerVC];
// if (playerVC.readyForDisplay) {
[playerVC.player play];
// }
});
}];
});
// 1.AVPlayer
}
@end
......@@ -47,10 +47,13 @@ class ScanImagePlugn {
return await channel.invokeMethod("IOS_IMAGE_BY_PATH", path);
}
static Future<Map> ios_album_item(
MethodChannel channel, String path) async {
static Future<Map> ios_album_item(MethodChannel channel, String path) async {
return await channel.invokeMethod("IOS_IMAGE_ITEM", path);
}
static Future<bool> playAlbumVideo(MethodChannel channel, String path) async {
return await channel.invokeMethod("play_album_video", path);
}
}
class ScanImageItem {
......
......@@ -31,6 +31,10 @@ class GengmeiFlutterPlugin {
return await ScanImagePlugn.ios_album_item(_channel, path);
}
static Future<bool> playAlbumVideo(String path) async {
return await ScanImagePlugn.playAlbumVideo(_channel, path);
}
static Future<bool> quitPage() async {
return await ScanImagePlugn.quitPage(_channel);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment