@@ -8,7 +8,7 @@ import 'package:dart_vlc_ffi/src/playerState/playerState.dart';
8
8
9
9
class Control extends StatefulWidget {
10
10
final Widget child;
11
- final int playerId ;
11
+ final Player player ;
12
12
final bool ? showTimeLeft;
13
13
final double ? progressBarThumbRadius;
14
14
final double ? progressBarThumbGlowRadius;
@@ -24,7 +24,7 @@ class Control extends StatefulWidget {
24
24
25
25
Control ({
26
26
required this .child,
27
- required this .playerId ,
27
+ required this .player ,
28
28
required this .showTimeLeft,
29
29
required this .progressBarThumbRadius,
30
30
required this .progressBarThumbGlowRadius,
@@ -51,37 +51,37 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
51
51
late StreamSubscription <PlaybackState > playPauseStream;
52
52
late AnimationController playPauseController;
53
53
54
+ Player get player => widget.player;
55
+
54
56
@override
55
57
void initState () {
56
58
super .initState ();
57
- this .playPauseController = new AnimationController (
58
- vsync: this , duration: Duration (milliseconds: 400 ));
59
- this .playPauseStream = players[widget.playerId]!
60
- .playbackStream
61
- .listen ((event) => this .setPlaybackMode (event.isPlaying));
62
- if (players[widget.playerId]! .playback.isPlaying)
63
- this .playPauseController.forward ();
59
+ playPauseController =
60
+ AnimationController (vsync: this , duration: Duration (milliseconds: 400 ));
61
+ playPauseStream = player.playbackStream
62
+ .listen ((event) => setPlaybackMode (event.isPlaying));
63
+ if (player.playback.isPlaying) playPauseController.forward ();
64
64
}
65
65
66
66
@override
67
67
void dispose () {
68
- this . playPauseStream.cancel ();
68
+ playPauseStream.cancel ();
69
69
super .dispose ();
70
70
}
71
71
72
72
void setPlaybackMode (bool isPlaying) {
73
73
if (isPlaying)
74
- this . playPauseController.forward ();
74
+ playPauseController.forward ();
75
75
else
76
- this . playPauseController.reverse ();
77
- this . setState (() {});
76
+ playPauseController.reverse ();
77
+ setState (() {});
78
78
}
79
79
80
80
@override
81
81
Widget build (BuildContext context) {
82
82
return GestureDetector (
83
83
onTap: () {
84
- if (players[widget.playerId] ! .playback.isPlaying) {
84
+ if (player .playback.isPlaying) {
85
85
if (_displayTapped) {
86
86
setState (() {
87
87
_hideControls = true ;
@@ -132,7 +132,7 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
132
132
padding:
133
133
EdgeInsets .only (bottom: 60 , right: 20 , left: 20 ),
134
134
child: StreamBuilder <PositionState >(
135
- stream: players[widget.playerId] ? .positionStream,
135
+ stream: player .positionStream,
136
136
builder: (BuildContext context,
137
137
AsyncSnapshot <PositionState > snapshot) {
138
138
final durationState = snapshot.data;
@@ -161,7 +161,7 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
161
161
: TimeLabelType .totalTime,
162
162
timeLabelTextStyle: widget.progressBarTextStyle,
163
163
onSeek: (duration) {
164
- players[widget.playerId] ! .seek (duration);
164
+ player .seek (duration);
165
165
},
166
166
),
167
167
);
@@ -181,7 +181,7 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
181
181
color: Colors .white,
182
182
iconSize: 30 ,
183
183
icon: Icon (Icons .skip_previous),
184
- onPressed: () => players[widget.playerId] ! .back (),
184
+ onPressed: () => player .back (),
185
185
),
186
186
SizedBox (width: 50 ),
187
187
IconButton (
@@ -190,15 +190,12 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
190
190
icon: Icon (Icons .replay_10),
191
191
onPressed: () {
192
192
int positionInMilliseconds =
193
- players[widget.playerId]!
194
- .position
195
- .position
196
- ? .inMilliseconds ??
193
+ player.position.position? .inMilliseconds ??
197
194
0 ;
198
195
if (! (positionInMilliseconds - 10000 )
199
196
.isNegative)
200
197
positionInMilliseconds -= 10000 ;
201
- players[widget.playerId] ! .seek (Duration (
198
+ player .seek (Duration (
202
199
milliseconds: positionInMilliseconds));
203
200
setState (() {});
204
201
}),
@@ -208,16 +205,14 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
208
205
iconSize: 30 ,
209
206
icon: AnimatedIcon (
210
207
icon: AnimatedIcons .play_pause,
211
- progress: this . playPauseController),
208
+ progress: playPauseController),
212
209
onPressed: () {
213
- if (players[widget.playerId]!
214
- .playback
215
- .isPlaying) {
216
- players[widget.playerId]! .pause ();
217
- this .playPauseController.reverse ();
210
+ if (player.playback.isPlaying) {
211
+ player.pause ();
212
+ playPauseController.reverse ();
218
213
} else {
219
- players[widget.playerId] ! .play ();
220
- this . playPauseController.forward ();
214
+ player .play ();
215
+ playPauseController.forward ();
221
216
}
222
217
},
223
218
),
@@ -228,21 +223,15 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
228
223
icon: Icon (Icons .forward_10),
229
224
onPressed: () {
230
225
int durationInMilliseconds =
231
- players[widget.playerId]!
232
- .position
233
- .duration
234
- ? .inMilliseconds ??
226
+ player.position.duration? .inMilliseconds ??
235
227
0 ;
236
228
int positionInMilliseconds =
237
- players[widget.playerId]!
238
- .position
239
- .position
240
- ? .inMilliseconds ??
229
+ player.position.position? .inMilliseconds ??
241
230
1 ;
242
231
if ((positionInMilliseconds + 10000 ) <=
243
232
durationInMilliseconds) {
244
233
positionInMilliseconds += 10000 ;
245
- players[widget.playerId] ! .seek (Duration (
234
+ player .seek (Duration (
246
235
milliseconds: positionInMilliseconds));
247
236
setState (() {});
248
237
}
@@ -252,7 +241,7 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
252
241
color: Colors .white,
253
242
iconSize: 30 ,
254
243
icon: Icon (Icons .skip_next),
255
- onPressed: () => players[widget.playerId] ! .next (),
244
+ onPressed: () => player .next (),
256
245
),
257
246
],
258
247
),
@@ -264,7 +253,7 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
264
253
crossAxisAlignment: CrossAxisAlignment .end,
265
254
children: [
266
255
VolumeControl (
267
- playerId : widget.playerId ,
256
+ player : player ,
268
257
thumbColor: widget.volumeThumbColor,
269
258
inactiveColor: widget.volumeInactiveColor,
270
259
activeColor: widget.volumeActiveColor,
@@ -274,7 +263,7 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
274
263
iconSize: 24 ,
275
264
icon: Icon (Icons .speaker, color: Colors .white),
276
265
onSelected: (Device device) {
277
- players[widget.playerId] ! .setDevice (device);
266
+ player .setDevice (device);
278
267
setState (() {});
279
268
},
280
269
itemBuilder: (context) {
@@ -305,22 +294,22 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
305
294
}
306
295
307
296
void _cancelAndRestartTimer () {
308
- this . _hideTimer? .cancel ();
297
+ _hideTimer? .cancel ();
309
298
310
- if (this . mounted) {
311
- this . _startHideTimer ();
299
+ if (mounted) {
300
+ _startHideTimer ();
312
301
313
- this . setState (() {
302
+ setState (() {
314
303
_hideControls = false ;
315
304
_displayTapped = true ;
316
305
});
317
306
}
318
307
}
319
308
320
309
void _startHideTimer () {
321
- this . _hideTimer = Timer (const Duration (seconds: 3 ), () {
322
- if (this . mounted) {
323
- this . setState (() {
310
+ _hideTimer = Timer (const Duration (seconds: 3 ), () {
311
+ if (mounted) {
312
+ setState (() {
324
313
_hideControls = true ;
325
314
});
326
315
}
@@ -329,14 +318,14 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
329
318
}
330
319
331
320
class VolumeControl extends StatefulWidget {
332
- final int playerId ;
321
+ final Player player ;
333
322
final Color ? activeColor;
334
323
final Color ? inactiveColor;
335
324
final Color ? backgroundColor;
336
325
final Color ? thumbColor;
337
326
338
327
const VolumeControl ({
339
- required this .playerId ,
328
+ required this .player ,
340
329
required this .activeColor,
341
330
required this .inactiveColor,
342
331
required this .backgroundColor,
@@ -353,6 +342,8 @@ class _VolumeControlState extends State<VolumeControl> {
353
342
bool _showVolume = false ;
354
343
double unmutedVolume = 0.5 ;
355
344
345
+ Player get player => widget.player;
346
+
356
347
@override
357
348
Widget build (BuildContext context) {
358
349
return Column (
@@ -387,9 +378,9 @@ class _VolumeControlState extends State<VolumeControl> {
387
378
child: Slider (
388
379
min: 0.0 ,
389
380
max: 1.0 ,
390
- value: players[widget.playerId] ! .general.volume,
381
+ value: player .general.volume,
391
382
onChanged: (volume) {
392
- players[widget.playerId] ! .setVolume (volume);
383
+ player .setVolume (volume);
393
384
setState (() {});
394
385
},
395
386
),
@@ -418,20 +409,20 @@ class _VolumeControlState extends State<VolumeControl> {
418
409
}
419
410
420
411
IconData getIcon () {
421
- if (players[widget.playerId] ! .general.volume > .5 )
412
+ if (player .general.volume > .5 )
422
413
return Icons .volume_up_sharp;
423
- else if (players[widget.playerId] ! .general.volume > 0 )
414
+ else if (player .general.volume > 0 )
424
415
return Icons .volume_down_sharp;
425
416
else
426
417
return Icons .volume_off_sharp;
427
418
}
428
419
429
420
void muteUnmute () {
430
- if (players[widget.playerId] ! .general.volume > 0 ) {
431
- unmutedVolume = players[widget.playerId] ! .general.volume;
432
- players[widget.playerId] ! .setVolume (0 );
421
+ if (player .general.volume > 0 ) {
422
+ unmutedVolume = player .general.volume;
423
+ player .setVolume (0 );
433
424
} else {
434
- players[widget.playerId] ! .setVolume (unmutedVolume);
425
+ player .setVolume (unmutedVolume);
435
426
}
436
427
setState (() {});
437
428
}
0 commit comments