Skip to content

Commit 8f9f5ea

Browse files
committed
[plugin] Added FFI configuration for Windows
1 parent 03d4bdb commit 8f9f5ea

File tree

5 files changed

+70
-60
lines changed

5 files changed

+70
-60
lines changed

example/lib/main.dart

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ class DartVLCExampleState extends State<DartVLCExample> {
238238
ElevatedButton(
239239
onPressed: () => this.setState(() {
240240
this.player.open(
241-
new Playlist(
242-
medias: this.medias,
243-
playlistMode:PlaylistMode.single
244-
),
245-
);
241+
new Playlist(
242+
medias: this.medias,
243+
playlistMode:
244+
PlaylistMode.single),
245+
);
246246
}),
247247
child: Text(
248248
'Open',
@@ -291,14 +291,23 @@ class DartVLCExampleState extends State<DartVLCExample> {
291291
color: Colors.transparent,
292292
),
293293
Slider(
294-
min: 0,
295-
max: this.position.duration?.inMilliseconds.toDouble() ?? 1.0,
296-
value: this.position.position?.inMilliseconds.toDouble() ?? 0.0,
297-
onChanged: (double position) =>
298-
this.player.seek(
299-
Duration(milliseconds: position.toInt())
300-
)
301-
),
294+
min: 0,
295+
max: this
296+
.position
297+
.duration
298+
?.inMilliseconds
299+
.toDouble() ??
300+
1.0,
301+
value: this
302+
.position
303+
.position
304+
?.inMilliseconds
305+
.toDouble() ??
306+
0.0,
307+
onChanged: (double position) => this
308+
.player
309+
.seek(Duration(
310+
milliseconds: position.toInt()))),
302311
Text('Event streams.'),
303312
Divider(
304313
height: 8.0,
@@ -659,12 +668,12 @@ class DartVLCExampleState extends State<DartVLCExample> {
659668
/// I ask all Flutter engineers to please fix this issue.
660669
/// Peace.
661670
/// 🙏🙏🙏
662-
///
671+
///
663672
/// Issue:
664673
/// https://github.com/flutter/flutter/issues/24786
665674
/// Prevention:
666675
/// https://stackoverflow.com/a/54164333/12825435
667-
///
676+
///
668677
if (finalIndex > this.current.medias.length)
669678
finalIndex = this.current.medias.length;
670679
if (initialIndex < finalIndex) finalIndex--;

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ packages:
4242
name: dart_vlc_ffi
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "0.0.3"
45+
version: "0.0.4"
4646
ffi:
4747
dependency: transitive
4848
description:

lib/dart_vlc.dart

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* GNU Lesser General Public License v2.1
99
*/
1010

11-
1211
// ignore_for_file: implementation_imports
1312
import 'dart:io';
1413
import 'dart:typed_data';
@@ -18,38 +17,40 @@ import 'package:dart_vlc_ffi/dart_vlc_ffi.dart' as FFI;
1817
export 'package:dart_vlc_ffi/dart_vlc_ffi.dart' hide DartVLC;
1918
export 'package:dart_vlc/src/widgets/video.dart';
2019

21-
2220
/// Initializes the DartVLC plugin.
23-
///
21+
///
2422
/// ```dart
2523
/// void main() {
2624
/// DartVLC.initialize();
2725
/// runApp(MyApp());
2826
/// }
2927
/// ```
30-
///
28+
///
3129
abstract class DartVLC {
3230
static void initialize() {
3331
FFI.videoFrameCallback = (int playerId, Uint8List videoFrame) {
34-
if (videoStreamControllers[playerId] != null && FFI.players[playerId] != null) {
35-
videoStreamControllers[playerId]!.add(
36-
new VideoFrame(
32+
if (videoStreamControllers[playerId] != null &&
33+
FFI.players[playerId] != null) {
34+
videoStreamControllers[playerId]!.add(new VideoFrame(
3735
playerId: playerId,
3836
videoWidth: FFI.players[playerId]!.videoWidth,
3937
videoHeight: FFI.players[playerId]!.videoHeight,
40-
byteArray: videoFrame
41-
)
42-
);
38+
byteArray: videoFrame));
4339
}
4440
};
41+
if (Platform.isWindows) {
42+
String directory = Platform.resolvedExecutable
43+
.split('\\')
44+
.sublist(0, Platform.resolvedExecutable.split('\\').length - 1)
45+
.join('\\');
46+
FFI.DartVLC.initialize(directory + '\\' + 'dart_vlc.dll');
47+
}
4548
if (Platform.isLinux) {
4649
String directory = Platform.resolvedExecutable
47-
.split('/')
48-
.sublist(0, Platform.resolvedExecutable.split('/').length - 1)
49-
.join('/');
50-
FFI.DartVLC.initialize(
51-
directory + '/lib/' + 'libdartvlc.so'
52-
);
50+
.split('/')
51+
.sublist(0, Platform.resolvedExecutable.split('/').length - 1)
52+
.join('/');
53+
FFI.DartVLC.initialize(directory + '/lib/' + 'libdartvlc.so');
5354
}
5455
}
5556
}

lib/src/widgets/controls.dart

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:dart_vlc_ffi/src/device.dart';
66
import 'package:dart_vlc_ffi/src/player.dart';
77
import 'package:dart_vlc_ffi/src/playerState/playerState.dart';
88

9-
109
class Control extends StatefulWidget {
1110
final Widget child;
1211
final int playerId;
@@ -56,17 +55,17 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
5655
late AnimationController playPauseController;
5756

5857
@override
59-
void initState() {
58+
void initState() {
6059
super.initState();
6160
this.playPauseController = new AnimationController(
62-
vsync: this,
63-
duration: Duration(milliseconds: 400)
64-
);
61+
vsync: this, duration: Duration(milliseconds: 400));
6562
}
6663

6764
void setPlaybackMode(bool isPlaying) {
68-
if (isPlaying) this.playPauseController.forward();
69-
else this.playPauseController.reverse();
65+
if (isPlaying)
66+
this.playPauseController.forward();
67+
else
68+
this.playPauseController.reverse();
7069
}
7170

7271
@override
@@ -195,23 +194,24 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
195194
if (!(positionInMilliseconds - 10000)
196195
.isNegative)
197196
positionInMilliseconds -= 10000;
198-
players[widget.playerId]!.seek(Duration(milliseconds: positionInMilliseconds));
197+
players[widget.playerId]!.seek(Duration(
198+
milliseconds: positionInMilliseconds));
199199
setState(() {});
200200
}),
201201
SizedBox(width: 20),
202202
IconButton(
203203
color: Colors.white,
204204
iconSize: 30,
205205
icon: AnimatedIcon(
206-
icon: AnimatedIcons.play_pause,
207-
progress: this.playPauseController
208-
),
206+
icon: AnimatedIcons.play_pause,
207+
progress: this.playPauseController),
209208
onPressed: () {
210-
if (players[widget.playerId]!.playback.isPlaying) {
209+
if (players[widget.playerId]!
210+
.playback
211+
.isPlaying) {
211212
players[widget.playerId]!.pause();
212213
this.playPauseController.reverse();
213-
}
214-
else {
214+
} else {
215215
players[widget.playerId]!.play();
216216
this.playPauseController.forward();
217217
}
@@ -238,10 +238,8 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
238238
if ((positionInMilliseconds + 10000) <=
239239
durationInMilliseconds) {
240240
positionInMilliseconds += 10000;
241-
players[widget.playerId]!
242-
.seek(Duration(
243-
milliseconds:
244-
positionInMilliseconds));
241+
players[widget.playerId]!.seek(Duration(
242+
milliseconds: positionInMilliseconds));
245243
setState(() {});
246244
}
247245
}),
@@ -276,16 +274,17 @@ class ControlState extends State<Control> with SingleTickerProviderStateMixin {
276274
setState(() {});
277275
},
278276
itemBuilder: (context) {
279-
return Devices.all.map(
280-
(device) => PopupMenuItem(
281-
child: Text(device.name,
282-
style: TextStyle(
283-
fontSize: 14.0,
284-
)),
285-
value: device,
286-
),
287-
)
288-
.toList();
277+
return Devices.all
278+
.map(
279+
(device) => PopupMenuItem(
280+
child: Text(device.name,
281+
style: TextStyle(
282+
fontSize: 14.0,
283+
)),
284+
value: device,
285+
),
286+
)
287+
.toList();
289288
},
290289
),
291290
],

lib/src/widgets/video.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:dart_vlc/src/widgets/controls.dart';
88

99
/// Internally used map to keep [GlobalKey]s for [Video]'s [ControlState]s.
1010
Map<int, GlobalKey<ControlState>> controls = {};
11+
1112
/// Internally used map to keep [StreamController]s for [Video] [Widget]s.
1213
Map<int, StreamController<VideoFrame>> videoStreamControllers = {};
1314

0 commit comments

Comments
 (0)