Skip to content

Commit

Permalink
perf: remove win32 package native window creation & add platform chan…
Browse files Browse the repository at this point in the history
…nel impl
  • Loading branch information
alexmercerind committed May 5, 2022
1 parent c926954 commit 496d1d5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 101 deletions.
26 changes: 26 additions & 0 deletions lib/channel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file is a part of dart_vlc (https://github.com/alexmercerind/dart_vlc)
//
// Copyright (C) 2021-2022 Hitesh Kumar Saini <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import 'package:flutter/services.dart';

/// Platform channel for using [Texture] & flutter::TextureRegistrar on Windows.
const channel = MethodChannel('dart_vlc');

const kPlayerRegisterTexture = 'PlayerRegisterTexture';
const kPlayerUnregisterTexture = 'PlayerUnregisterTexture';
const kPlayerCreateHWND = 'PlayerCreateHWND';
12 changes: 4 additions & 8 deletions lib/dart_vlc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_native_view/flutter_native_view.dart';
import 'package:path/path.dart' as path;
import 'package:flutter/services.dart';

import 'package:dart_vlc/channel.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, Player;
export 'package:dart_vlc/src/widgets/video.dart';
export 'package:dart_vlc/src/widgets/native_video.dart';

/// Platform channel for using [Texture] & flutter::TextureRegistrar on Windows.
const _channel = MethodChannel('dart_vlc');

/// 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].
Expand Down Expand Up @@ -73,16 +69,16 @@ class Player extends FFI.Player {
commandlineArguments: commandlineArguments) {
() async {
if (registerTexture) {
textureId.value = await _channel
.invokeMethod('PlayerRegisterTexture', {'playerId': id});
textureId.value = await channel
.invokeMethod(kPlayerRegisterTexture, {'playerId': id});
}
}();
}

@override
void dispose() async {
if (registerTexture) {
await _channel.invokeMethod('PlayerUnregisterTexture', {'playerId': id});
await channel.invokeMethod(kPlayerUnregisterTexture, {'playerId': id});
}
textureId.value = null;
super.dispose();
Expand Down
82 changes: 0 additions & 82 deletions lib/src/hwnd.dart

This file was deleted.

27 changes: 17 additions & 10 deletions lib/src/widgets/native_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import 'dart:async';

import 'package:dart_vlc/src/hwnd.dart';
import 'package:dart_vlc/channel.dart';
import 'package:flutter/material.dart';

import 'package:dart_vlc/dart_vlc.dart';
Expand Down Expand Up @@ -169,15 +169,22 @@ class _NativeVideoState extends State<NativeVideo> {
@override
void initState() {
super.initState();
createHWND().then((handle) {
widget.player.setHWND(handle);
setState(() {
controller = NativeViewController(
handle: handle,
hitTestBehavior: HitTestBehavior.opaque,
);
});
});
channel.invokeMethod(
kPlayerCreateHWND,
{
'playerId': playerId,
},
).then(
(handle) {
widget.player.setHWND(handle);
setState(() {
controller = NativeViewController(
handle: handle,
hitTestBehavior: HitTestBehavior.opaque,
);
});
},
);
if (widget.showControls) {
controls[playerId] = controlKey;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ abstract class _VideoStateBase extends State<Video>
return Container(
width: widget.width ?? double.infinity,
height: widget.height ?? double.infinity,
color: Colors.black,
color: Colors.transparent,
child: widget.showControls
? Control(
key: controlKey,
Expand Down

0 comments on commit 496d1d5

Please sign in to comment.