Skip to content
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
wants to merge 14 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/CHANGELOG.md
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``.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void main() {
late Future<int> textureId;

setUp(() {
VideoPlayerPlatform.instance = VideoPlayerPlugin();
VideoPlayerPlatform.instance = VideoPlayerPlugin()
..mode = VideoRenderMode.html;
textureId = VideoPlayerPlatform.instance
.create(
DataSource(
Expand Down
Copy link
Member

@ditman ditman Mar 11, 2024

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?

Copy link
Author

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.

Copy link
Member

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.

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;
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,9 @@ class VideoPlayer {
}
return durationRange;
}

/// Returns the [web.HTMLVideoElement] associated with this player
web.HTMLVideoElement get videoElement {
return _videoElement;
}
}
Loading