diff --git a/packages/video_player/video_player_web/example/integration_test/video_player_test.dart b/packages/video_player/video_player_web/example/integration_test/video_player_test.dart index 8156b7b48024..d5ede903cda4 100644 --- a/packages/video_player/video_player_web/example/integration_test/video_player_test.dart +++ b/packages/video_player/video_player_web/example/integration_test/video_player_test.dart @@ -356,6 +356,56 @@ void main() { expect(video.getAttribute('disableRemotePlayback'), 'true'); }); }); + + group('when called first time', () { + testWidgets('expect correct options', (WidgetTester tester) async { + await player.setOptions( + const VideoPlayerWebOptions( + controls: VideoPlayerWebOptionsControls.enabled( + allowDownload: false, + allowFullscreen: false, + allowPlaybackRate: false, + allowPictureInPicture: false, + ), + allowContextMenu: false, + allowRemotePlayback: false, + ), + ); + + expect(video.controls, isTrue); + expect(video.controlsList, isNotNull); + expect(video.controlsList?.length, 3); + expect(video.controlsList?.contains('nodownload'), isTrue); + expect(video.controlsList?.contains('nofullscreen'), isTrue); + expect(video.controlsList?.contains('noplaybackrate'), isTrue); + expect(video.getAttribute('disablePictureInPicture'), 'true'); + expect(video.getAttribute('disableRemotePlayback'), 'true'); + }); + + group('when called once more', () { + testWidgets('expect correct options', (WidgetTester tester) async { + await player.setOptions( + const VideoPlayerWebOptions( + // ignore: avoid_redundant_argument_values + controls: VideoPlayerWebOptionsControls.disabled(), + // ignore: avoid_redundant_argument_values + allowContextMenu: true, + // ignore: avoid_redundant_argument_values + allowRemotePlayback: true, + ), + ); + + expect(video.controls, isFalse); + expect(video.controlsList, isNotNull); + expect(video.controlsList?.length, 0); + expect(video.controlsList?.contains('nodownload'), isFalse); + expect(video.controlsList?.contains('nofullscreen'), isFalse); + expect(video.controlsList?.contains('noplaybackrate'), isFalse); + expect(video.getAttribute('disablePictureInPicture'), isNull); + expect(video.getAttribute('disableRemotePlayback'), isNull); + }); + }); + }); }); }); } diff --git a/packages/video_player/video_player_web/lib/src/video_player.dart b/packages/video_player/video_player_web/lib/src/video_player.dart index 343c136859e2..9eed4d3f0ed5 100644 --- a/packages/video_player/video_player_web/lib/src/video_player.dart +++ b/packages/video_player/video_player_web/lib/src/video_player.dart @@ -205,6 +205,9 @@ class VideoPlayer { /// Sets options Future setOptions(VideoPlayerWebOptions options) async { + // incase called multiple times, reset options + _resetOptions(); + if (options.controls.enabled) { _videoElement.controls = true; final String controlsList = options.controls.controlsList; @@ -227,11 +230,30 @@ class VideoPlayer { } } + void _resetOptions() { + _videoElement.controls = false; + if (_videoElement.hasAttribute('controlsList')) { + _videoElement.setAttribute('controlsList', ''); + } + if (_videoElement.hasAttribute('disablePictureInPicture')) { + _videoElement.setAttribute('disablePictureInPicture', false); + } + if (_onContextMenu != null) { + _videoElement.removeEventListener('contextmenu', _onContextMenu); + _onContextMenu = null; + } + if (_videoElement.hasAttribute('disableRemotePlayback')) { + _videoElement.setAttribute('disableRemotePlayback', false); + } + } + /// Disposes of the current [html.VideoElement]. void dispose() { _videoElement.removeAttribute('src'); - _videoElement.removeEventListener('contextmenu', _onContextMenu); - _onContextMenu = null; + if (_onContextMenu != null) { + _videoElement.removeEventListener('contextmenu', _onContextMenu); + _onContextMenu = null; + } _videoElement.load(); }