-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[video_player_web] Add an alternate mode that renders images directly into the canvas #6286
Open
jezell
wants to merge
14
commits into
flutter:main
Choose a base branch
from
jezell:video_player_render_as_texture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+561
−12
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
11e88cf
Add support for rendering videos on web without wasting platform layers
jezell 8e7c2e9
update video player web version
jezell a988220
update changelog
jezell 4897da7
dispose images when no longer needed
jezell 460eddc
abstract video player renderer logic and element creation
jezell 7f2fb7b
add support for firefox
jezell b313a41
close intermediate bitmapsource (fixes leak in Firefox)
jezell acca14d
fix dart analyze, optimize capture to skip RAF frames when not playin…
jezell fbbcb1f
add auto mode to video renderer to dynamically choose appropriate ren…
jezell d91aa8c
remove unsafe hasProperty
jezell bfdbf0c
default auto to textures in chrome since it handles them better than …
jezell 718ea8a
fix cors error on existing tests
jezell e2ae7eb
only set crossOrigin attribute when non html mode
jezell 4ebf0df
fix dart analyze
jezell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2.4.0 | ||
|
||
* Adds VideoPlugin.renderVideoAsTexture | ||
|
||
## 2.3.0 | ||
|
||
* Migrates package and tests to `package:web``. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/video_player/video_player_web/lib/src/browser_detection.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:web/web.dart' as web; | ||
|
||
/// Browser detection copied from engine/browser_detection.dart | ||
|
||
/// The HTML engine used by the current browser. | ||
enum BrowserEngine { | ||
/// The engine that powers Chrome, Samsung Internet Browser, UC Browser, | ||
/// Microsoft Edge, Opera, and others. | ||
/// | ||
/// Blink is assumed in case when a more precise browser engine wasn't | ||
/// detected. | ||
blink, | ||
|
||
/// The engine that powers Safari. | ||
webkit, | ||
|
||
/// The engine that powers Firefox. | ||
firefox, | ||
} | ||
|
||
/// html webgl version qualifier constants. | ||
abstract class WebGLVersion { | ||
/// WebGL 1.0 is based on OpenGL ES 2.0 / GLSL 1.00 | ||
static const int webgl1 = 1; | ||
|
||
/// WebGL 2.0 is based on OpenGL ES 3.0 / GLSL 3.00 | ||
static const int webgl2 = 2; | ||
} | ||
|
||
/// Lazily initialized current browser engine. | ||
final BrowserEngine _browserEngine = _detectBrowserEngine(); | ||
|
||
/// Override the value of [browserEngine]. | ||
/// | ||
/// Setting this to `null` lets [browserEngine] detect the browser that the | ||
/// app is running on. | ||
/// | ||
/// This is intended to be used for testing and debugging only. | ||
BrowserEngine? debugBrowserEngineOverride; | ||
|
||
/// Returns the [BrowserEngine] used by the current browser. | ||
/// | ||
/// This is used to implement browser-specific behavior. | ||
BrowserEngine get browserEngine { | ||
return debugBrowserEngineOverride ?? _browserEngine; | ||
} | ||
|
||
BrowserEngine _detectBrowserEngine() { | ||
final String vendor = web.window.navigator.vendor; | ||
final String agent = web.window.navigator.userAgent.toLowerCase(); | ||
return detectBrowserEngineByVendorAgent(vendor, agent); | ||
} | ||
|
||
/// Detects browser engine for a given vendor and agent string. | ||
/// | ||
/// Used for testing this library. | ||
BrowserEngine detectBrowserEngineByVendorAgent(String vendor, String agent) { | ||
if (vendor == 'Google Inc.') { | ||
return BrowserEngine.blink; | ||
} else if (vendor == 'Apple Computer, Inc.') { | ||
return BrowserEngine.webkit; | ||
} else if (agent.contains('Edg/')) { | ||
// Chromium based Microsoft Edge has `Edg` in the user-agent. | ||
// https://docs.microsoft.com/en-us/microsoft-edge/web-platform/user-agent-string | ||
return BrowserEngine.blink; | ||
} else if (vendor == '' && agent.contains('firefox')) { | ||
// An empty string means firefox: | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vendor | ||
return BrowserEngine.firefox; | ||
} | ||
|
||
// Assume Blink otherwise, but issue a warning. | ||
// ignore: avoid_print | ||
print( | ||
'WARNING: failed to detect current browser engine. Assuming this is a Chromium-compatible browser.'); | ||
return BrowserEngine.blink; | ||
} | ||
|
||
/// Whether the current browser is Safari. | ||
bool get isSafari => browserEngine == BrowserEngine.webkit; | ||
|
||
/// Whether the current browser is Firefox. | ||
bool get isFirefox => browserEngine == BrowserEngine.firefox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole file should be provided by flutter web engine, so the decision is always in sync?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ditman yeah, that file is in the browser engine, but can it be imported from here? It would definitely be ideal to not have to double implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it can't be imported now, it needs to be reexported from the
ui_web
package to work.