Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/widgets/story_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> requestHeaders,
Key key}) {
return StoryVideo(
VideoLoader(url, requestHeaders: requestHeaders),
storyController: controller,
key: key,
isHLS: isHLS
);
}

Expand All @@ -79,14 +82,21 @@ class StoryVideoState extends State<StoryVideo> {

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) {
Expand Down Expand Up @@ -114,7 +124,7 @@ class StoryVideoState extends State<StoryVideo> {
);
}

return widget.videoLoader.state == LoadState.loading
return widget.videoLoader.state == LoadState.loading || !playerController.value.initialized
? Center(
child: Container(
width: 70,
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/story_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class StoryItem {
BoxFit imageFit = BoxFit.fitWidth,
String caption,
bool shown = false,
bool isHLS = false,
Map<String, dynamic> requestHeaders,
}) {
return StoryItem(
Expand All @@ -228,6 +229,7 @@ class StoryItem {
StoryVideo.url(
url,
controller: controller,
isHLS: isHLS,
requestHeaders: requestHeaders,
),
SafeArea(
Expand Down