From d9df0fb7c032c912ae2d1fe456e2372b0f6434d4 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Sat, 6 Apr 2024 16:37:02 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E9=80=82=E9=85=8D=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../image_picker_ohos/example/lib/main.dart | 29 ++++++++++------ .../example/ohos/entry/oh-package.json5 | 15 +------- .../image_picker_ohos/example/pubspec.yaml | 5 ++- .../lib/image_picker_ohos.dart | 34 +++++++++++++++---- .../ets/image_picker/ImagePickerDelegate.ets | 14 +++++++- 5 files changed, 65 insertions(+), 32 deletions(-) diff --git a/packages/image_picker/image_picker_ohos/example/lib/main.dart b/packages/image_picker/image_picker_ohos/example/lib/main.dart index fd568fbc1..803cd8e55 100644 --- a/packages/image_picker/image_picker_ohos/example/lib/main.dart +++ b/packages/image_picker/image_picker_ohos/example/lib/main.dart @@ -74,18 +74,18 @@ class _MyHomePageState extends State { final TextEditingController maxHeightController = TextEditingController(); final TextEditingController qualityController = TextEditingController(); - Future _playVideo(XFile? file) async { + Future _playVideo(int? file) async { if (file != null && mounted) { await _disposeVideoController(); late VideoPlayerController controller; - controller = VideoPlayerController.file(File(file.path)); + controller = VideoPlayerController.fileFd(file); _controller = controller; const double volume = 1.0; - await controller.setVolume(volume); - await controller.initialize(); - await controller.setLooping(true); - await controller.play(); + unawaited(controller.setVolume(volume)); + unawaited(controller.initialize()); + unawaited(controller.setLooping(true)); + unawaited(controller.play()); setState(() {}); } } @@ -106,7 +106,8 @@ class _MyHomePageState extends State { if (file != null && context.mounted) { _showPickedSnackBar(context, [file]); } - await _playVideo(file); + final int fileFd = (_picker as ImagePickerOhos).getFileFd(file?.path); + await _playVideo(fileFd); } else if (isMultiImage) { await _displayPickImageDialog(context, (double? maxWidth, double? maxHeight, int? quality) async { @@ -225,9 +226,16 @@ class _MyHomePageState extends State { textAlign: TextAlign.center, ); } + final Map fileFdlist = (_picker as ImagePickerOhos).fileFdlist; + String path = ''; + for(final String? key in fileFdlist.keys){ + if(fileFdlist[key].toString() == _controller!.dataSource.split('//')[1]){ + path = key!.split('/').last; + } + } return Padding( padding: const EdgeInsets.all(10.0), - child: AspectRatioVideo(_controller), + child: Column(children: [Text(path), AspectRatioVideo(_controller)]) ); } @@ -284,7 +292,7 @@ class _MyHomePageState extends State { Widget _buildInlineVideoPlayer(int index) { final VideoPlayerController controller = - VideoPlayerController.file(File(_mediaFileList![index].path)); + VideoPlayerController.fileFd((_picker as ImagePickerOhos).getFileFd(_mediaFileList![index].path)); const double volume = 1.0; controller.setVolume(volume); controller.initialize(); @@ -309,7 +317,8 @@ class _MyHomePageState extends State { if (response.file != null) { if (response.type == RetrieveType.video) { _isVideo = true; - await _playVideo(response.file); + final int fileFd = (_picker as ImagePickerOhos).getFileFd(response.file?.path); + await _playVideo(fileFd); } else { _isVideo = false; setState(() { diff --git a/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 b/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 index c3f83b0d3..a991b5dfb 100644 --- a/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 +++ b/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 @@ -1,17 +1,3 @@ -/* -* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ { name: 'entry', version: '1.0.0', @@ -23,5 +9,6 @@ '@ohos/flutter_ohos': 'file:../har/flutter.har', '@ohos/integration_test': 'file:./har/integration_test.har', '@ohos/image_picker_ohos': 'file:./har/image_picker_ohos.har', + '@ohos/video_player_ohos': 'file:./har/video_player_ohos.har', }, } \ No newline at end of file diff --git a/packages/image_picker/image_picker_ohos/example/pubspec.yaml b/packages/image_picker/image_picker_ohos/example/pubspec.yaml index e06013a15..b8d675cde 100644 --- a/packages/image_picker/image_picker_ohos/example/pubspec.yaml +++ b/packages/image_picker/image_picker_ohos/example/pubspec.yaml @@ -34,7 +34,10 @@ dependencies: path: ../ image_picker_platform_interface: ^2.8.0 mime: ^1.0.4 - video_player: ^2.1.4 + video_player: + git: + url: "https://gitee.com/openharmony-sig/flutter_packages.git" + path: "packages/video_player/video_player" dev_dependencies: build_runner: ^2.1.10 diff --git a/packages/image_picker/image_picker_ohos/lib/image_picker_ohos.dart b/packages/image_picker/image_picker_ohos/lib/image_picker_ohos.dart index 296a19971..75ba1b6c7 100644 --- a/packages/image_picker/image_picker_ohos/lib/image_picker_ohos.dart +++ b/packages/image_picker/image_picker_ohos/lib/image_picker_ohos.dart @@ -22,6 +22,7 @@ class ImagePickerOhos extends ImagePickerPlatform { : _hostApi = api ?? ImagePickerApi(); final ImagePickerApi _hostApi; + final Map fileFdlist = new Map(); bool useOhosPhotoPicker = false; static void registerWith() { ImagePickerPlatform.instance = ImagePickerOhos(); @@ -67,7 +68,7 @@ class ImagePickerOhos extends ImagePickerPlatform { double? maxWidth, double? maxHeight, int? imageQuality, - }) { + }) async { if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { throw ArgumentError.value( imageQuality, 'imageQuality', 'must be between 0 and 100'); @@ -81,7 +82,7 @@ class ImagePickerOhos extends ImagePickerPlatform { throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative'); } - return _hostApi.pickImages( + final List path = await _hostApi.pickImages( SourceSpecification(type: SourceType.gallery), ImageSelectionOptions( maxWidth: maxWidth, @@ -90,6 +91,14 @@ class ImagePickerOhos extends ImagePickerPlatform { GeneralOptions( allowMultiple: true, usePhotoPicker: useOhosPhotoPicker), ); + + List pathList = []; + + for(int i = 0 ; i _getImagePath({ @@ -154,9 +163,17 @@ class ImagePickerOhos extends ImagePickerPlatform { usePhotoPicker: useOhosPhotoPicker, ), ); + fileFdlist[paths.first] = int.parse(paths[1] ?? '0'); return paths.isEmpty ? null : paths.first; } + int getFileFd(String? file) { + if(file == null){ + return 0; + } + return fileFdlist[file]!; + } + @override Future getImage({ required ImageSource source, @@ -213,15 +230,20 @@ class ImagePickerOhos extends ImagePickerPlatform { Future> getMedia({ required MediaOptions options, }) async { - return (await _hostApi.pickMedia( + final List paths = await _hostApi.pickMedia( _mediaOptionsToMediaSelectionOptions(options), GeneralOptions( allowMultiple: options.allowMultiple, usePhotoPicker: useOhosPhotoPicker, ), - )) - .map((String? path) => XFile(path!)) - .toList(); + ); + final List pathList = []; + for(int i = 1; i< paths.length; i+=2){ + fileFdlist[paths[i-1]] = int.parse(paths[i] ?? '0'); + pathList.add(paths[i - 1]); + } + + return pathList.map((String? path) => XFile(path!).toList()); } @override diff --git a/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets b/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets index 12aa195b5..46591eccd 100644 --- a/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets +++ b/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets @@ -265,6 +265,9 @@ export default class ImagePickerDelegate { abilityAccessCtrl.createAtManager() .requestPermissionsFromUser(this.context, ['ohos.permission.READ_MEDIA']) .then(async (permission) => { + if(permission.authResults[0] !== 0){ + return + } let result: ESObject = null; if (this.context) { result = await this.context.startAbilityForResult(want); @@ -483,10 +486,12 @@ export default class ImagePickerDelegate { if (path != null) { let realPath = FileUtils.getPathFromUri(this.context as Context, path); Log.i(ImagePickerDelegate.TAG, "realPath :" + realPath); + let file = fs.openSync(realPath, fs.OpenMode.READ_ONLY); if (realPath != null) { path = realPath; } - pathList.add(path); + pathList.add(realPath) + pathList.add(file.fd.toString()); } let localResult: Result> | null = null; @@ -518,6 +523,13 @@ export default class ImagePickerDelegate { } else if (path) { Log.i(ImagePickerDelegate.TAG, path[0]); + let pathList: ArrayList = new ArrayList(); + for (let i = 0; i < path.length; i++) { + const element: string = path[i]; + let file = fs.openSync(element); + pathList.add(element); + pathList.add(file.fd.toString()); + } localResult.success(path as ArrayList); } } -- Gitee From bff4a245a5c3e6a989c6dbedc4b88ff36727734b Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Sat, 6 Apr 2024 17:35:46 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E9=80=82=E9=85=8D=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../image_picker/image_picker_ohos/lib/image_picker_ohos.dart | 2 +- .../src/main/ets/image_picker/ImagePickerDelegate.ets | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/image_picker/image_picker_ohos/lib/image_picker_ohos.dart b/packages/image_picker/image_picker_ohos/lib/image_picker_ohos.dart index 75ba1b6c7..6c08de09e 100644 --- a/packages/image_picker/image_picker_ohos/lib/image_picker_ohos.dart +++ b/packages/image_picker/image_picker_ohos/lib/image_picker_ohos.dart @@ -243,7 +243,7 @@ class ImagePickerOhos extends ImagePickerPlatform { pathList.add(paths[i - 1]); } - return pathList.map((String? path) => XFile(path!).toList()); + return pathList.map((String? path) => XFile(path!)).toList(); } @override diff --git a/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets b/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets index 46591eccd..cb1d31ed1 100644 --- a/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets +++ b/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets @@ -530,7 +530,7 @@ export default class ImagePickerDelegate { pathList.add(element); pathList.add(file.fd.toString()); } - localResult.success(path as ArrayList); + localResult.success(pathList as ArrayList); } } -- Gitee From 7a8a6441ee0881273cb53374c916e017e7854d5a Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Sun, 7 Apr 2024 15:35:51 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E9=80=82=E9=85=8D=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../example/ohos/entry/oh-package.json5 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 b/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 index a991b5dfb..184fe3a0c 100644 --- a/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 +++ b/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 @@ -1,3 +1,17 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ { name: 'entry', version: '1.0.0', -- Gitee From a25049113ba17b61beb10c3d343e17ff67bb9219 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Sun, 7 Apr 2024 18:31:40 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E9=80=82=E9=85=8D=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../image_picker_ohos/example/ohos/entry/src/main/module.json5 | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/image_picker/image_picker_ohos/example/ohos/entry/src/main/module.json5 b/packages/image_picker/image_picker_ohos/example/ohos/entry/src/main/module.json5 index 7bbf78b18..bd577753f 100644 --- a/packages/image_picker/image_picker_ohos/example/ohos/entry/src/main/module.json5 +++ b/packages/image_picker/image_picker_ohos/example/ohos/entry/src/main/module.json5 @@ -48,6 +48,7 @@ ], "requestPermissions": [ {"name" : "ohos.permission.INTERNET"}, + {"name" : "ohos.permission.READ_MEDIA"} ] } } \ No newline at end of file -- Gitee From 57534791b7bc5e30e1ee50ddee6ecdb7dd558ed5 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Mon, 8 Apr 2024 10:50:22 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E9=80=82=E9=85=8D=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../image_picker_ohos/example/ohos/entry/oh-package.json5 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 b/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 index 184fe3a0c..2812cb621 100644 --- a/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 +++ b/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 @@ -20,9 +20,5 @@ author: '', license: '', dependencies: { - '@ohos/flutter_ohos': 'file:../har/flutter.har', - '@ohos/integration_test': 'file:./har/integration_test.har', - '@ohos/image_picker_ohos': 'file:./har/image_picker_ohos.har', - '@ohos/video_player_ohos': 'file:./har/video_player_ohos.har', }, } \ No newline at end of file -- Gitee From 275bf3197eeb5a8918759ae41a8fc1d775dc85e4 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Mon, 8 Apr 2024 14:01:58 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E9=80=82=E9=85=8D=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../image_picker_ohos/example/ohos/entry/oh-package.json5 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 b/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 index 2812cb621..184fe3a0c 100644 --- a/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 +++ b/packages/image_picker/image_picker_ohos/example/ohos/entry/oh-package.json5 @@ -20,5 +20,9 @@ author: '', license: '', dependencies: { + '@ohos/flutter_ohos': 'file:../har/flutter.har', + '@ohos/integration_test': 'file:./har/integration_test.har', + '@ohos/image_picker_ohos': 'file:./har/image_picker_ohos.har', + '@ohos/video_player_ohos': 'file:./har/video_player_ohos.har', }, } \ No newline at end of file -- Gitee