@@ -12,9 +12,6 @@ import 'package:web/web.dart' as web;
12
12
13
13
import 'src/video_player.dart' ;
14
14
15
- // TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views.
16
- // ignore_for_file: avoid_renaming_method_parameters
17
-
18
15
/// The web implementation of [VideoPlayerPlatform] .
19
16
///
20
17
/// This class implements the `package:video_player` functionality for the web.
@@ -24,21 +21,20 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
24
21
VideoPlayerPlatform .instance = VideoPlayerPlugin ();
25
22
}
26
23
27
- // Map of textureId -> VideoPlayer instances
24
+ // Map of playerId -> VideoPlayer instances.
28
25
final Map <int , VideoPlayer > _videoPlayers = < int , VideoPlayer > {};
29
26
30
- // Simulate the native "textureId".
31
- int _textureCounter = 1 ;
27
+ int _playerCounter = 1 ;
32
28
33
29
@override
34
30
Future <void > init () async {
35
31
return _disposeAllPlayers ();
36
32
}
37
33
38
34
@override
39
- Future <void > dispose (int textureId ) async {
40
- _player (textureId ).dispose ();
41
- _videoPlayers.remove (textureId );
35
+ Future <void > dispose (int playerId ) async {
36
+ _player (playerId ).dispose ();
37
+ _videoPlayers.remove (playerId );
42
38
return ;
43
39
}
44
40
@@ -50,8 +46,22 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
50
46
}
51
47
52
48
@override
53
- Future <int > create (DataSource dataSource) async {
54
- final int textureId = _textureCounter++ ;
49
+ Future <int > create (DataSource dataSource) {
50
+ return createWithOptions (
51
+ VideoCreationOptions (
52
+ dataSource: dataSource,
53
+ // Web only supports platform views.
54
+ viewType: VideoViewType .platformView,
55
+ ),
56
+ );
57
+ }
58
+
59
+ @override
60
+ Future <int > createWithOptions (VideoCreationOptions options) async {
61
+ // Parameter options.viewType is ignored because web only supports platform views.
62
+
63
+ final DataSource dataSource = options.dataSource;
64
+ final int playerId = _playerCounter++ ;
55
65
56
66
late String uri;
57
67
switch (dataSource.sourceType) {
@@ -75,68 +85,68 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
75
85
}
76
86
77
87
final web.HTMLVideoElement videoElement = web.HTMLVideoElement ()
78
- ..id = 'videoElement-$textureId '
88
+ ..id = 'videoElement-$playerId '
79
89
..style.border = 'none'
80
90
..style.height = '100%'
81
91
..style.width = '100%' ;
82
92
83
93
// TODO(hterkelsen): Use initialization parameters once they are available
84
94
ui_web.platformViewRegistry.registerViewFactory (
85
- 'videoPlayer-$textureId ' , (int viewId) => videoElement);
95
+ 'videoPlayer-$playerId ' , (int viewId) => videoElement);
86
96
87
97
final VideoPlayer player = VideoPlayer (videoElement: videoElement)
88
98
..initialize (
89
99
src: uri,
90
100
);
91
101
92
- _videoPlayers[textureId ] = player;
102
+ _videoPlayers[playerId ] = player;
93
103
94
- return textureId ;
104
+ return playerId ;
95
105
}
96
106
97
107
@override
98
- Future <void > setLooping (int textureId , bool looping) async {
99
- return _player (textureId ).setLooping (looping);
108
+ Future <void > setLooping (int playerId , bool looping) async {
109
+ return _player (playerId ).setLooping (looping);
100
110
}
101
111
102
112
@override
103
- Future <void > play (int textureId ) async {
104
- return _player (textureId ).play ();
113
+ Future <void > play (int playerId ) async {
114
+ return _player (playerId ).play ();
105
115
}
106
116
107
117
@override
108
- Future <void > pause (int textureId ) async {
109
- return _player (textureId ).pause ();
118
+ Future <void > pause (int playerId ) async {
119
+ return _player (playerId ).pause ();
110
120
}
111
121
112
122
@override
113
- Future <void > setVolume (int textureId , double volume) async {
114
- return _player (textureId ).setVolume (volume);
123
+ Future <void > setVolume (int playerId , double volume) async {
124
+ return _player (playerId ).setVolume (volume);
115
125
}
116
126
117
127
@override
118
- Future <void > setPlaybackSpeed (int textureId , double speed) async {
119
- return _player (textureId ).setPlaybackSpeed (speed);
128
+ Future <void > setPlaybackSpeed (int playerId , double speed) async {
129
+ return _player (playerId ).setPlaybackSpeed (speed);
120
130
}
121
131
122
132
@override
123
- Future <void > seekTo (int textureId , Duration position) async {
124
- return _player (textureId ).seekTo (position);
133
+ Future <void > seekTo (int playerId , Duration position) async {
134
+ return _player (playerId ).seekTo (position);
125
135
}
126
136
127
137
@override
128
- Future <Duration > getPosition (int textureId ) async {
129
- return _player (textureId ).getPosition ();
138
+ Future <Duration > getPosition (int playerId ) async {
139
+ return _player (playerId ).getPosition ();
130
140
}
131
141
132
142
@override
133
- Stream <VideoEvent > videoEventsFor (int textureId ) {
134
- return _player (textureId ).events;
143
+ Stream <VideoEvent > videoEventsFor (int playerId ) {
144
+ return _player (playerId ).events;
135
145
}
136
146
137
147
@override
138
- Future <void > setWebOptions (int textureId , VideoPlayerWebOptions options) {
139
- return _player (textureId ).setOptions (options);
148
+ Future <void > setWebOptions (int playerId , VideoPlayerWebOptions options) {
149
+ return _player (playerId ).setOptions (options);
140
150
}
141
151
142
152
// Retrieves a [VideoPlayer] by its internal `id`.
@@ -146,11 +156,11 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
146
156
}
147
157
148
158
@override
149
- Widget buildView (int textureId ) {
150
- return HtmlElementView (viewType: 'videoPlayer-$textureId ' );
159
+ Widget buildView (int playerId ) {
160
+ return HtmlElementView (viewType: 'videoPlayer-$playerId ' );
151
161
}
152
162
153
- /// Sets the audio mode to mix with other sources (ignored)
163
+ /// Sets the audio mode to mix with other sources (ignored).
154
164
@override
155
165
Future <void > setMixWithOthers (bool mixWithOthers) => Future <void >.value ();
156
166
}
0 commit comments