-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[video_player] Miscellaneous fixes to improve video player in web. #2819
Changes from all commits
92f7bcc
0ff1d97
36edf4c
cbaf030
dcf5fed
22f8998
c9eede9
85e1f6b
74de285
7e9e3f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,10 +66,12 @@ class VideoPlayerPlugin extends VideoPlayerPlatform { | |
| final int textureId = _textureCounter; | ||
| _textureCounter++; | ||
|
|
||
| Uri uri; | ||
| String uri; | ||
| switch (dataSource.sourceType) { | ||
| case DataSourceType.network: | ||
| uri = Uri.parse(dataSource.uri); | ||
| // Do NOT modify the incoming uri, it can be a Blob, and Safari doesn't | ||
| // like blobs that have changed. | ||
| uri = dataSource.uri; | ||
| break; | ||
| case DataSourceType.asset: | ||
| String assetUrl = dataSource.asset; | ||
|
|
@@ -79,7 +81,7 @@ class VideoPlayerPlugin extends VideoPlayerPlatform { | |
| // 'webOnlyAssetManager' is only in the web version of dart:ui | ||
| // ignore: undefined_prefixed_name | ||
| assetUrl = ui.webOnlyAssetManager.getAssetUrl(assetUrl); | ||
| uri = Uri.parse(assetUrl); | ||
| uri = assetUrl; | ||
| break; | ||
| case DataSourceType.file: | ||
| return Future.error(UnimplementedError( | ||
|
|
@@ -145,18 +147,21 @@ class _VideoPlayer { | |
| final StreamController<VideoEvent> eventController = | ||
| StreamController<VideoEvent>(); | ||
|
|
||
| final Uri uri; | ||
| final String uri; | ||
| final int textureId; | ||
| VideoElement videoElement; | ||
| bool isInitialized = false; | ||
|
|
||
| void initialize() { | ||
| videoElement = VideoElement() | ||
| ..src = uri.toString() | ||
| ..src = uri | ||
| ..autoplay = false | ||
| ..controls = false | ||
| ..style.border = 'none'; | ||
|
|
||
| // Allows Safari iOS to play the video inline | ||
| videoElement.setAttribute('playsinline', 'true'); | ||
|
|
||
| // TODO(hterkelsen): Use initialization parameters once they are available | ||
| // ignore: undefined_prefixed_name | ||
| ui.platformViewRegistry.registerViewFactory( | ||
|
|
@@ -218,6 +223,12 @@ class _VideoPlayer { | |
| } | ||
|
|
||
| void setVolume(double value) { | ||
| // TODO: Do we need to expose a "muted" API? https://github.com/flutter/flutter/issues/60721 | ||
| if (value > 0.0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might need to introduce a small epsilon when comparing float values
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or we make the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This "hatch" is only there so web users can do: setVolume(0.0) and get a "muted" player. About making the There's a huge API surface for the For this PR I was only trying to make the selected video auto-play in the image_picker web example, not do any significant changes to the API of the video_player widget.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created this issue so we can discuss this API change: If we decide to add a "muted" attribute to the public API, this hack can be removed! |
||
| videoElement.muted = false; | ||
| } else { | ||
| videoElement.muted = true; | ||
| } | ||
| videoElement.volume = value; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.