Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: video_player web options
  • Loading branch information
defuncart committed Aug 22, 2023
commit e490ed6a6857e4e2b1174704e62b9fe0255eea97
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class VideoPlayer {

final StreamController<VideoEvent> _eventController;
final html.VideoElement _videoElement;
void Function(html.Event)? _onContextMenu;

bool _isInitialized = false;
bool _isBuffering = false;
Expand Down Expand Up @@ -202,9 +203,27 @@ class VideoPlayer {
return Duration(milliseconds: (_videoElement.currentTime * 1000).round());
}

/// Sets options
Future<void> setOptions(VideoPlayerWebOptions options) async {
if (options.controlsEnabled) {
_videoElement.controls = true;
final String controlsList = options.controlsList;
if (controlsList.isNotEmpty) {
_videoElement.setAttribute('controlsList', controlsList);
}
}

if (!options.allowContextMenu) {
_onContextMenu = (html.Event event) => event.preventDefault();
_videoElement.addEventListener('contextmenu', _onContextMenu);
}
}

/// Disposes of the current [html.VideoElement].
void dispose() {
_videoElement.removeAttribute('src');
_videoElement.removeEventListener('contextmenu', _onContextMenu);
_onContextMenu = null;
_videoElement.load();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
return _player(textureId).events;
}

@override
Future<void> setWebOptions(int textureId, VideoPlayerWebOptions options) {
return _player(textureId).setOptions(options);
}

// Retrieves a [VideoPlayer] by its internal `id`.
// It must have been created earlier from the [create] method.
VideoPlayer _player(int id) {
Expand Down