Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[video_player_web] Playback speed #3081

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 @@
## 0.1.4

* Added option to set the video playback speed on the video controller.

## 0.1.3+2

* Allow users to set the 'muted' attribute on video elements by setting their volume to 0.
Expand Down
13 changes: 13 additions & 0 deletions packages/video_player/video_player_web/lib/video_player_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
return _videoPlayers[textureId].setVolume(volume);
}

@override
Future<void> setPlaybackSpeed(int textureId, double speed) async {
assert(speed > 0);

return _videoPlayers[textureId].setPlaybackSpeed(speed);
}

@override
Future<void> seekTo(int textureId, Duration position) async {
return _videoPlayers[textureId].seekTo(position);
Expand Down Expand Up @@ -232,6 +239,12 @@ class _VideoPlayer {
videoElement.volume = value;
}

void setPlaybackSpeed(double speed) {
assert(speed > 0);

videoElement.playbackRate = speed;
}

void seekTo(Duration position) {
videoElement.currentTime = position.inMilliseconds.toDouble() / 1000;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: video_player_web
description: Web platform implementation of video_player
description: Web platform implementation of video_player.
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_web
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.1.3+2
version: 0.1.4

flutter:
plugin:
Expand All @@ -19,7 +19,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
meta: ^1.1.7
video_player_platform_interface: ^2.0.0
video_player_platform_interface: ^2.2.0

dev_dependencies:
flutter_test:
Expand All @@ -29,5 +29,5 @@ dev_dependencies:
pedantic: ^1.8.0

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.8.0 <3.0.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am changing this here just to be consistent with the platform interface (the platform interface requires it because of pigeon v0.1.7, which annotates it on a file in preparation of null safety).

flutter: ">=1.12.8 <2.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ void main() {
expect(VideoPlayerPlatform.instance.setVolume(textureId, 0.8), completes);
});

test('can set playback speed', () {
expect(
VideoPlayerPlatform.instance.setPlaybackSpeed(textureId, 2.0),
completes,
);
});

test('can seek to position', () {
expect(
VideoPlayerPlatform.instance.seekTo(textureId, Duration(seconds: 1)),
Expand Down