From 5d62e956833ae288a7a66a6d6c6ac54d78b2b3d6 Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Fri, 5 Jul 2024 16:37:05 +0545 Subject: [PATCH 1/8] fix: Video uniqueness issue --- lib/src/controllers/pod_player_controller.dart | 3 ++- pubspec.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/controllers/pod_player_controller.dart b/lib/src/controllers/pod_player_controller.dart index 229ce884..5bd1f7ed 100644 --- a/lib/src/controllers/pod_player_controller.dart +++ b/lib/src/controllers/pod_player_controller.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:universal_html/html.dart' as uni_html; +import 'package:uuid/uuid.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; import '../../pod_player.dart'; @@ -29,7 +30,7 @@ class PodPlayerController { } void _init() { - getTag = UniqueKey().toString(); + getTag = const Uuid().v4(); Get.config(enableLog: PodVideoPlayer.enableGetxLogs); _ctr = Get.put(PodGetXVideoController(), permanent: true, tag: getTag) ..config( diff --git a/pubspec.yaml b/pubspec.yaml index c04b2050..5fd8843c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pod_player description: Vimeo and youtube player for flutter, Pod player provides customizable video player controls that support android, ios and web. -version: 0.2.2 +version: 0.2.3 homepage: https://github.com/newtaDev/pod_player environment: @@ -17,6 +17,7 @@ dependencies: wakelock_plus: ^1.2.4 universal_html: ^2.2.4 youtube_explode_dart: ^2.2.0 + uuid: ^4.4.0 dev_dependencies: flutter_test: From d6a505194cdb4cf9aa4bfbc82c4b08b45a1930d1 Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Fri, 30 Aug 2024 09:10:59 +0545 Subject: [PATCH 2/8] refactor: Add in-memory caching of Vimeo urls --- .../controllers/pod_url_cache_singleton.dart | 25 +++++++++++++++++++ lib/src/utils/video_apis.dart | 10 ++++++++ 2 files changed, 35 insertions(+) create mode 100644 lib/src/controllers/pod_url_cache_singleton.dart diff --git a/lib/src/controllers/pod_url_cache_singleton.dart b/lib/src/controllers/pod_url_cache_singleton.dart new file mode 100644 index 00000000..b21446bc --- /dev/null +++ b/lib/src/controllers/pod_url_cache_singleton.dart @@ -0,0 +1,25 @@ +import '../../pod_player.dart'; + +class PodUrlCacheSingleton { + static final PodUrlCacheSingleton _singleton = + PodUrlCacheSingleton._internal(); + + factory PodUrlCacheSingleton() { + return _singleton; + } + + PodUrlCacheSingleton._internal(); + + final Map> _podPreFetchMap = {}; + + /// Add a list of urls to the pre-fetch list. + void addUrls(String key, List urls) { + _podPreFetchMap[key] = urls; + } + + /// Get the list of urls from the pre-fetch list. + List getUrls(String key) { + final urls = _podPreFetchMap[key] ?? []; + return urls; + } +} diff --git a/lib/src/utils/video_apis.dart b/lib/src/utils/video_apis.dart index 69153a19..e080b98d 100644 --- a/lib/src/utils/video_apis.dart +++ b/lib/src/utils/video_apis.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'package:http/http.dart'; import 'package:youtube_explode_dart/youtube_explode_dart.dart'; +import '../controllers/pod_url_cache_singleton.dart'; import '../models/vimeo_models.dart'; String podErrorString(String val) { @@ -84,6 +85,12 @@ class VideoApis { String videoId, Map httpHeader, ) async { + final podCache = PodUrlCacheSingleton(); + final cachedUrls = podCache.getUrls(videoId); + if (cachedUrls.isNotEmpty) { + return cachedUrls; + } + try { final response = await http.get( Uri.parse('https://api.vimeo.com/videos/$videoId'), @@ -106,6 +113,9 @@ class VideoApis { ); } } + + podCache.addUrls(videoId, list); + return list; } catch (error) { if (error.toString().contains('XMLHttpRequest')) { From 9ebb2f51d411c711267faced7525b96c411aeddd Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Fri, 30 Aug 2024 09:11:58 +0545 Subject: [PATCH 3/8] release: v0.2.4 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5fd8843c..ee316e05 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pod_player description: Vimeo and youtube player for flutter, Pod player provides customizable video player controls that support android, ios and web. -version: 0.2.3 +version: 0.2.4 homepage: https://github.com/newtaDev/pod_player environment: From a5abb7131dd30fe99e34cd2685741037267a48b3 Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Tue, 3 Sep 2024 13:26:46 +0545 Subject: [PATCH 4/8] refactor: Export video apis --- lib/pod_player.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pod_player.dart b/lib/pod_player.dart index e7a0d631..1420b406 100644 --- a/lib/pod_player.dart +++ b/lib/pod_player.dart @@ -12,4 +12,5 @@ export 'src/models/pod_progress_bar_config.dart'; export 'src/models/vimeo_models.dart'; export 'src/pod_player.dart'; export 'src/utils/enums.dart'; +export 'src/utils/video_apis.dart'; export 'src/widgets/pod_progress_bar.dart'; From 9f53b31f8319c011d015b1463fe9b23b3b8b6f0c Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Tue, 3 Sep 2024 13:26:59 +0545 Subject: [PATCH 5/8] release: 0.2.5 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index ee316e05..4112eb8b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pod_player description: Vimeo and youtube player for flutter, Pod player provides customizable video player controls that support android, ios and web. -version: 0.2.4 +version: 0.2.5 homepage: https://github.com/newtaDev/pod_player environment: From 5744b25c8fed45f2b0d90bbfed5a61ab98a1fff2 Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Tue, 26 Nov 2024 09:37:31 +0545 Subject: [PATCH 6/8] refactor: Rely on UniqueKey --- lib/src/controllers/pod_player_controller.dart | 3 +-- pubspec.yaml | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/src/controllers/pod_player_controller.dart b/lib/src/controllers/pod_player_controller.dart index 5bd1f7ed..229ce884 100644 --- a/lib/src/controllers/pod_player_controller.dart +++ b/lib/src/controllers/pod_player_controller.dart @@ -3,7 +3,6 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:universal_html/html.dart' as uni_html; -import 'package:uuid/uuid.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; import '../../pod_player.dart'; @@ -30,7 +29,7 @@ class PodPlayerController { } void _init() { - getTag = const Uuid().v4(); + getTag = UniqueKey().toString(); Get.config(enableLog: PodVideoPlayer.enableGetxLogs); _ctr = Get.put(PodGetXVideoController(), permanent: true, tag: getTag) ..config( diff --git a/pubspec.yaml b/pubspec.yaml index 4112eb8b..c99988ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,6 @@ dependencies: wakelock_plus: ^1.2.4 universal_html: ^2.2.4 youtube_explode_dart: ^2.2.0 - uuid: ^4.4.0 dev_dependencies: flutter_test: From d26724d7e092ccaa8e02f5a03e81b061fd1b5d4c Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Tue, 26 Nov 2024 10:24:49 +0545 Subject: [PATCH 7/8] refactor: Add preloading for other urls --- lib/src/utils/video_apis.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/src/utils/video_apis.dart b/lib/src/utils/video_apis.dart index e080b98d..1edbec5e 100644 --- a/lib/src/utils/video_apis.dart +++ b/lib/src/utils/video_apis.dart @@ -29,6 +29,12 @@ class VideoApis { String videoId, String? hash, ) async { + final podCache = PodUrlCacheSingleton(); + final cachedUrls = podCache.getUrls(videoId); + if (cachedUrls.isNotEmpty) { + return cachedUrls; + } + try { final response = await _makeRequestHash(videoId, hash); final jsonData = jsonDecode(response.body)['request']['files']; @@ -67,6 +73,8 @@ class VideoApis { ); } + podCache.addUrls(videoId, vimeoQualityUrls); + return vimeoQualityUrls; } catch (error) { if (error.toString().contains('XMLHttpRequest')) { @@ -134,6 +142,12 @@ class VideoApis { String youtubeIdOrUrl, bool live, ) async { + final podCache = PodUrlCacheSingleton(); + final cachedUrls = podCache.getUrls(youtubeIdOrUrl); + if (cachedUrls.isNotEmpty) { + return cachedUrls; + } + try { final yt = YoutubeExplode(); final urls = []; @@ -161,6 +175,9 @@ class VideoApis { } // Close the YoutubeExplode's http client. yt.close(); + + podCache.addUrls(youtubeIdOrUrl, urls); + return urls; } catch (error) { if (error.toString().contains('XMLHttpRequest')) { From a208ed1a38b749f22b879a0ba1ab95cab5055c95 Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Tue, 26 Nov 2024 10:32:26 +0545 Subject: [PATCH 8/8] release: release-0.2.6 --- analysis_options.yaml | 1 - .../pod_getx_video_controller.dart | 75 ++++++++----------- .../controllers/pod_player_controller.dart | 1 - lib/src/controllers/pod_video_controller.dart | 2 +- .../core/overlays/web_dropdown_menu.dart | 3 - lib/src/widgets/core/pod_core_player.dart | 4 +- lib/src/widgets/doubble_tap_effect.dart | 2 +- pubspec.yaml | 2 +- 8 files changed, 37 insertions(+), 53 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 18aea978..13024eef 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -4,7 +4,6 @@ analyzer: missing_required_param: error prefer_const_declarations: warning prefer_const_constructors: warning - import_of_legacy_library_into_null_safe: warning public_member_api_docs: ignore language: strict-casts: true diff --git a/lib/src/controllers/pod_getx_video_controller.dart b/lib/src/controllers/pod_getx_video_controller.dart index 7a46d30d..168effa3 100644 --- a/lib/src/controllers/pod_getx_video_controller.dart +++ b/lib/src/controllers/pod_getx_video_controller.dart @@ -10,7 +10,6 @@ import 'package:wakelock_plus/wakelock_plus.dart'; import '../../pod_player.dart'; import '../utils/logger.dart'; -import '../utils/video_apis.dart'; part 'pod_base_controller.dart'; part 'pod_gestures_controller.dart'; @@ -93,7 +92,6 @@ class PodGetXVideoController extends _PodGesturesController { httpHeaders: playVideoFrom.httpHeaders, ); playingVideoUrl = playVideoFrom.dataSource; - break; case PodVideoPlayerType.networkQualityUrls: final url = await getUrlFromVideoQualityUrls( qualityList: podPlayerConfig.videoQualityPriority, @@ -110,7 +108,6 @@ class PodGetXVideoController extends _PodGesturesController { ); playingVideoUrl = url; - break; case PodVideoPlayerType.youtube: final urls = await getVideoQualityUrlsFromYoutube( playVideoFrom.dataSource!, @@ -131,7 +128,6 @@ class PodGetXVideoController extends _PodGesturesController { ); playingVideoUrl = url; - break; case PodVideoPlayerType.vimeo: await getQualityUrlsFromVimeoId( playVideoFrom.dataSource!, @@ -151,7 +147,6 @@ class PodGetXVideoController extends _PodGesturesController { ); playingVideoUrl = url; - break; case PodVideoPlayerType.asset: /// @@ -163,7 +158,6 @@ class PodGetXVideoController extends _PodGesturesController { ); playingVideoUrl = playVideoFrom.dataSource; - break; case PodVideoPlayerType.file: if (kIsWeb) { throw Exception('file doesnt support web'); @@ -176,7 +170,6 @@ class PodGetXVideoController extends _PodGesturesController { videoPlayerOptions: playVideoFrom.videoPlayerOptions, ); - break; case PodVideoPlayerType.vimeoPrivateVideos: await getQualityUrlsFromVimeoPrivateId( playVideoFrom.dataSource!, @@ -195,49 +188,49 @@ class PodGetXVideoController extends _PodGesturesController { httpHeaders: playVideoFrom.httpHeaders, ); playingVideoUrl = url; - - break; } } ///Listning on keyboard events void onKeyBoardEvents({ - required RawKeyEvent event, + required KeyEvent event, required BuildContext appContext, required String tag, }) { - if (kIsWeb) { - if (event.isKeyPressed(LogicalKeyboardKey.space)) { - togglePlayPauseVideo(); - return; - } - if (event.isKeyPressed(LogicalKeyboardKey.keyM)) { - toggleMute(); - return; - } - if (event.isKeyPressed(LogicalKeyboardKey.arrowLeft)) { - onLeftDoubleTap(); - return; - } - if (event.isKeyPressed(LogicalKeyboardKey.arrowRight)) { - onRightDoubleTap(); - return; - } - if (event.isKeyPressed(LogicalKeyboardKey.keyF) && - event.logicalKey.keyLabel == 'F') { - toggleFullScreenOnWeb(appContext, tag); - } - if (event.isKeyPressed(LogicalKeyboardKey.escape)) { - if (isFullScreen) { - uni_html.document.exitFullscreen(); - if (!isWebPopupOverlayOpen) { - disableFullScreen(appContext, tag); - } - } - } + if (!kIsWeb) return; + + if (event is! KeyDownEvent) { + return; + } + if (event.logicalKey == LogicalKeyboardKey.space) { + togglePlayPauseVideo(); return; } + if (event.logicalKey == LogicalKeyboardKey.keyM) { + toggleMute(); + return; + } + if (event.logicalKey == LogicalKeyboardKey.arrowLeft) { + onLeftDoubleTap(); + return; + } + if (event.logicalKey == LogicalKeyboardKey.arrowRight) { + onRightDoubleTap(); + return; + } + if (event.logicalKey == LogicalKeyboardKey.keyF && + event.logicalKey.keyLabel == 'F') { + toggleFullScreenOnWeb(appContext, tag); + } + if (event.logicalKey == LogicalKeyboardKey.escape) { + if (isFullScreen) { + uni_html.document.exitFullscreen(); + if (!isWebPopupOverlayOpen) { + disableFullScreen(appContext, tag); + } + } + } } void toggleFullScreenOnWeb(BuildContext context, String tag) { @@ -259,18 +252,14 @@ class PodGetXVideoController extends _PodGesturesController { case PodVideoState.playing: if (podPlayerConfig.wakelockEnabled) WakelockPlus.enable(); playVideo(true); - break; case PodVideoState.paused: if (podPlayerConfig.wakelockEnabled) WakelockPlus.disable(); playVideo(false); - break; case PodVideoState.loading: isShowOverlay(true); - break; case PodVideoState.error: if (podPlayerConfig.wakelockEnabled) WakelockPlus.disable(); playVideo(false); - break; } } diff --git a/lib/src/controllers/pod_player_controller.dart b/lib/src/controllers/pod_player_controller.dart index 229ce884..be99918c 100644 --- a/lib/src/controllers/pod_player_controller.dart +++ b/lib/src/controllers/pod_player_controller.dart @@ -7,7 +7,6 @@ import 'package:wakelock_plus/wakelock_plus.dart'; import '../../pod_player.dart'; import '../utils/logger.dart'; -import '../utils/video_apis.dart'; import 'pod_getx_video_controller.dart'; class PodPlayerController { diff --git a/lib/src/controllers/pod_video_controller.dart b/lib/src/controllers/pod_video_controller.dart index 0a0d4ea6..b4763b17 100644 --- a/lib/src/controllers/pod_video_controller.dart +++ b/lib/src/controllers/pod_video_controller.dart @@ -206,7 +206,7 @@ class _PodVideoController extends _PodUiController { SystemUiMode.manual, overlays: SystemUiOverlay.values, ), - ] + ], ]); } diff --git a/lib/src/widgets/core/overlays/web_dropdown_menu.dart b/lib/src/widgets/core/overlays/web_dropdown_menu.dart index 78965f89..783a8999 100644 --- a/lib/src/widgets/core/overlays/web_dropdown_menu.dart +++ b/lib/src/widgets/core/overlays/web_dropdown_menu.dart @@ -68,14 +68,11 @@ class _WebSettingsDropdownState extends State<_WebSettingsDropdown> { switch (settingsMenu) { case 'OUALITY': await _onVimeoQualitySelect(details, podCtr); - break; case 'SPEED': await _onPlaybackSpeedSelect(details, podCtr); - break; case 'LOOP': podCtr.isWebPopupOverlayOpen = false; await podCtr.toggleLooping(); - break; default: podCtr.isWebPopupOverlayOpen = false; } diff --git a/lib/src/widgets/core/pod_core_player.dart b/lib/src/widgets/core/pod_core_player.dart index 7a7a3e47..9dddf9ba 100644 --- a/lib/src/widgets/core/pod_core_player.dart +++ b/lib/src/widgets/core/pod_core_player.dart @@ -16,12 +16,12 @@ class _PodCoreVideoPlayer extends StatelessWidget { final podCtr = Get.find(tag: tag); return Builder( builder: (ctrx) { - return RawKeyboardListener( + return KeyboardListener( autofocus: true, focusNode: (podCtr.isFullScreen ? FocusNode() : podCtr.keyboardFocusWeb) ?? FocusNode(), - onKey: (value) => podCtr.onKeyBoardEvents( + onKeyEvent: (value) => podCtr.onKeyBoardEvents( event: value, appContext: ctrx, tag: tag, diff --git a/lib/src/widgets/doubble_tap_effect.dart b/lib/src/widgets/doubble_tap_effect.dart index f23915f9..a9570a5a 100644 --- a/lib/src/widgets/doubble_tap_effect.dart +++ b/lib/src/widgets/doubble_tap_effect.dart @@ -199,7 +199,7 @@ class _DoubleTapRippleEffectState extends State fillColor: widget.rippleColor, ), ), - ) + ), ], ), ), diff --git a/pubspec.yaml b/pubspec.yaml index c99988ab..293e6fa2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pod_player description: Vimeo and youtube player for flutter, Pod player provides customizable video player controls that support android, ios and web. -version: 0.2.5 +version: 0.2.6 homepage: https://github.com/newtaDev/pod_player environment: