From 6aebb3612814e7b7a30f8f8c39c22d9d82384e16 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 17 Jul 2020 16:57:46 +0200 Subject: [PATCH] support of streaming HLS urls for storyVideo widget --- lib/widgets/story_video.dart | 20 +++++++++++++++----- lib/widgets/story_view.dart | 2 ++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/widgets/story_video.dart b/lib/widgets/story_video.dart index 89f65f05..6f7c4e22 100644 --- a/lib/widgets/story_video.dart +++ b/lib/widgets/story_video.dart @@ -43,18 +43,21 @@ class VideoLoader { class StoryVideo extends StatefulWidget { final StoryController storyController; final VideoLoader videoLoader; + final bool isHLS; - StoryVideo(this.videoLoader, {this.storyController, Key key}) + StoryVideo(this.videoLoader, {this.storyController, this.isHLS = false, Key key}) : super(key: key ?? UniqueKey()); static StoryVideo url(String url, {StoryController controller, + bool isHLS, Map requestHeaders, Key key}) { return StoryVideo( VideoLoader(url, requestHeaders: requestHeaders), storyController: controller, key: key, + isHLS: isHLS ); } @@ -79,14 +82,21 @@ class StoryVideoState extends State { widget.videoLoader.loadVideo(() { if (widget.videoLoader.state == LoadState.success) { - this.playerController = - VideoPlayerController.file(widget.videoLoader.videoFile); + /// if video is HLS, need to load it from network, if is a downloaded file, need to load it from local cache + if (widget.isHLS){ + this.playerController = + VideoPlayerController.network(widget.videoLoader.url); + } else { + this.playerController = + VideoPlayerController.file(widget.videoLoader.videoFile); - playerController.initialize().then((v) { + } + this.playerController.initialize().then((v) { setState(() {}); widget.storyController.play(); }); + if (widget.storyController != null) { _streamSubscription = widget.storyController.playbackNotifier.listen((playbackState) { @@ -114,7 +124,7 @@ class StoryVideoState extends State { ); } - return widget.videoLoader.state == LoadState.loading + return widget.videoLoader.state == LoadState.loading || !playerController.value.initialized ? Center( child: Container( width: 70, diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index b1834a3a..b051631d 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -218,6 +218,7 @@ class StoryItem { BoxFit imageFit = BoxFit.fitWidth, String caption, bool shown = false, + bool isHLS = false, Map requestHeaders, }) { return StoryItem( @@ -228,6 +229,7 @@ class StoryItem { StoryVideo.url( url, controller: controller, + isHLS: isHLS, requestHeaders: requestHeaders, ), SafeArea(