Skip to content

Commit

Permalink
[plugin] Update interface for Windows & flutter::TextureRegistrar
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Aug 9, 2021
1 parent 872c6d7 commit e114385
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
73 changes: 72 additions & 1 deletion lib/dart_vlc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,83 @@
// ignore_for_file: implementation_imports
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/services.dart';

import 'package:dart_vlc/src/widgets/video.dart';
import 'package:dart_vlc_ffi/src/internal/ffi.dart' as FFI;
import 'package:dart_vlc_ffi/dart_vlc_ffi.dart' as FFI;
export 'package:dart_vlc_ffi/dart_vlc_ffi.dart' hide DartVLC;
export 'package:dart_vlc_ffi/dart_vlc_ffi.dart' hide DartVLC, Player;
export 'package:dart_vlc/src/widgets/video.dart';

/// Platform channel for using [Texture] & flutter::TextureRegistrar on Windows.
final MethodChannel _channel = MethodChannel('dart_vlc')
..setMethodCallHandler((call) async {
print(call.method);
});


/// A [Player] to open & play a [Media] or [Playlist] from file, network or asset.
///
/// Use [Player] constructor to create a new instance of a [Player].
/// Provide a unique [id] while instanciating.
///
/// ```dart
/// Player player = new Player(id: 0);
/// ```
///
/// If you wish to use this instance for [Video] playback, then provide [videoWidth] & [videoHeight] optional parameters.
/// Higher value may lead to degraded performance.
///
/// ```dart
/// Player player = new Player(
/// id: 0,
/// videoWidth: 1920,
/// videoHeight: 1080,
/// );
/// ```
///
/// Do not provide [videoWidth] & [videoHeight], if you wish to use the [Player] for only audio playback.
///
/// Use various methods & event streams avaiable to control & listen to events of the playback.
///
class Player extends FFI.Player {
int? textureId;

Player({
required int id,
int videoWidth: 0,
int videoHeight: 0,
List<String>? commandlineArguments
}) : super(id: id, videoWidth: videoWidth, videoHeight: videoHeight, commandlineArguments: commandlineArguments) {
if (this.videoHeight > 0 && this.videoWidth > 0 && Platform.isWindows) {
() async {
this.textureId = await _channel.invokeMethod(
'Player.onVideo',
{
'playerId': this.id,
'videoWidth': this.videoWidth,
'videoHeight': this.videoHeight
}
);
}();
}
}

@override
void dispose() {
super.dispose();
if (this.videoHeight > 0 && this.videoWidth > 0 && Platform.isWindows) {
_channel.invokeMethod(
'Player.dispose',
{
'playerId', this.id
}
);
}
}
}


/// Initializes the DartVLC plugin.
///
/// ```dart
Expand Down
19 changes: 19 additions & 0 deletions lib/src/experimental/video.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter/material.dart';
import 'package:dart_vlc/dart_vlc.dart';


class Video extends StatelessWidget {
final Player player;
const Video({Key? key, required this.player}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
height: 360,
width: 480,
child: Texture(
textureId: this.player.textureId!,
),
);
}
}

0 comments on commit e114385

Please sign in to comment.