Skip to content

Commit

Permalink
fix(android)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchuancong committed Sep 5, 2023
1 parent 48a5af3 commit eb63105
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
46 changes: 25 additions & 21 deletions lib/modules/live_play/widgets/video_player/video_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:developer';

import 'dart:io';

Expand Down Expand Up @@ -27,7 +28,6 @@ class VideoController with ChangeNotifier {
final bool autoPlay;
final videoFit = BoxFit.contain.obs;


ScreenBrightness brightnessController = ScreenBrightness();

final hasError = false.obs;
Expand All @@ -39,19 +39,18 @@ class VideoController with ChangeNotifier {
bool get supportPip => Platform.isAndroid;
bool get supportWindowFull => Platform.isWindows || Platform.isLinux;
bool get fullscreenUI => isFullscreen.value || isWindowFullscreen.value;
// Video player status
// Video player status
// A [GlobalKey<VideoState>] is required to access the programmatic fullscreen interface.
late final GlobalKey<media_kit_video.VideoState> key =
GlobalKey<media_kit_video.VideoState>();
// Create a [Player] to control playback.
late final player = Player();
// Create a [VideoController] to handle video output from [Player].
String? vo = Platform.isAndroid ? 'gpu' : 'libmpv';
String? hwdec = Platform.isAndroid ? 'mediacodec' : 'auto';
late final controller = media_kit_video.VideoController(player, configuration: media_kit_video.VideoControllerConfiguration(
enableHardwareAcceleration: false,
hwdec: hwdec
));
String? vo = Platform.isAndroid ? 'mediacodec_embed' : 'libmpv';
String? hwdec = Platform.isAndroid ? 'mediacodec' : 'auto';
late final controller = media_kit_video.VideoController(player,
configuration: media_kit_video.VideoControllerConfiguration(
enableHardwareAcceleration: true, vo: vo, hwdec: hwdec));
// Controller ui status
Timer? showControllerTimer;
final showController = true.obs;
Expand Down Expand Up @@ -114,17 +113,20 @@ class VideoController with ChangeNotifier {
void initVideoController() {
FlutterVolumeController.showSystemUI = false;
setDataSource(datasource);
player.stream.playing.listen((bool playing) {
controller.player.stream.playing.listen((bool playing) {
if (playing) {
isPlaying.value = true;
} else {
isPlaying.value = false;
}
});
// fix auto fullscreen
if (fullScreenByDefault && datasource.isNotEmpty) {
Timer(const Duration(milliseconds: 500), () => toggleFullScreen());
}
controller.player.stream.error.listen((String err) {
log(err);
});
// fix auto fullscreen
if (fullScreenByDefault && datasource.isNotEmpty) {
Timer(const Duration(milliseconds: 500), () => toggleFullScreen());
}
}

// Danmaku player control
Expand Down Expand Up @@ -210,10 +212,10 @@ class VideoController with ChangeNotifier {
player.playOrPause();
}

void toggleFullScreen() {
void toggleFullScreen() {
// disable locked
showLocked.value = false;
// fix danmaku overlap bug
// fix danmaku overlap bug
if (!hideDanmaku.value) {
hideDanmaku.value = true;
Timer(const Duration(milliseconds: 500), () {
Expand Down Expand Up @@ -262,11 +264,13 @@ class VideoController with ChangeNotifier {
enableController();
}

void enterPipMode(BuildContext context) async {}
void enterPipMode(BuildContext context) async {

}

// volumn & brightness
Future<double?> volumn() async {
return await FlutterVolumeController.getVolume();
return await FlutterVolumeController.getVolume();
}

Future<double> brightness() async {
Expand Down Expand Up @@ -359,10 +363,10 @@ class DesktopFullscreen extends StatelessWidget {
body: Stack(
children: [
media_kit_video.Video(
controller: controller.controller,
fit: controller.videoFit.value,
controls: (state) => VideoControllerPanel(controller: controller),
)
controller: controller.controller,
fit: controller.videoFit.value,
controls: (state) => VideoControllerPanel(controller: controller),
)
],
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class TopActionBar extends StatelessWidget {
const DatetimeInfo(),
BatteryInfo(controller: controller),
],
if (!controller.fullscreenUI && controller.supportPip)
PIPButton(controller: controller),
// if (!controller.fullscreenUI && controller.supportPip)
// PIPButton(controller: controller),
]),
),
),
Expand Down Expand Up @@ -346,6 +346,7 @@ class DanmakuViewer extends StatelessWidget {
controller: controller.danmakuController,
speed: controller.danmakuSpeed.value.toInt(),
maxBulletHeight: controller.danmakuFontSize * 1.5,
safeBottomHeight: 50,
massiveMode: false, // disabled by default
child: Container(),
),
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ packages:
dependency: "direct main"
description:
name: flutter_barrage
sha256: cc79a9bb08bcfd76e9856337c168f4b19e16916ca7bb6d929cc6f02663d3387c
sha256: d47404608dc66d4a08a5224179cfb4405aefe524f915d03dee4f5fab0cca3094
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.5.5"
version: "0.5.4"
flutter_blurhash:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies:
flutter_staggered_grid_view: ^0.7.0

# barrage wall
flutter_barrage: ^0.5.4
flutter_barrage: 0.5.4
flutter_exit_app: ^1.1.2

# database
Expand Down

0 comments on commit eb63105

Please sign in to comment.