Skip to content

Commit

Permalink
add wakelock
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmarmalade committed Sep 11, 2022
1 parent adeb12d commit b504070
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
5 changes: 5 additions & 0 deletions lib/pages/desktopplay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:ice_live_viewer/widgets/douyudanmaku.dart';
import 'package:ice_live_viewer/widgets/videoframe.dart';
import 'package:ice_live_viewer/widgets/bilibilianmaku.dart';
import 'package:ice_live_viewer/widgets/huyadanmaku.dart';
import 'package:wakelock/wakelock.dart';

class VlcPlayer extends StatefulWidget {
const VlcPlayer(
Expand Down Expand Up @@ -34,6 +35,8 @@ class _VlcPlayerState extends State<VlcPlayer> {

@override
Widget build(BuildContext context) {
Wakelock.enable();
Wakelock.enabled.then((value) => print('Wakelock:$value'));
final ratio =
MediaQuery.of(context).size.width / MediaQuery.of(context).size.height;
final nativeVideo = Video(player: streamPlayer, showControls: false);
Expand All @@ -51,6 +54,8 @@ class _VlcPlayerState extends State<VlcPlayer> {
onPressed: () {
Navigator.pop(context);
streamPlayer.stop();
Wakelock.disable();
Wakelock.enabled.then((value) => print('Wakelock:$value'));
},
),
title: Text(widget.title),
Expand Down
63 changes: 38 additions & 25 deletions lib/pages/mobileplay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:ice_live_viewer/widgets/huyadanmaku.dart';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
import 'package:ice_live_viewer/widgets/douyudanmaku.dart';
import 'package:wakelock/wakelock.dart';

class MobilePlayer extends StatefulWidget {
const MobilePlayer(
Expand Down Expand Up @@ -45,6 +46,8 @@ class _MobilePlayerState extends State<MobilePlayer> {

@override
Widget build(BuildContext context) {
Wakelock.enable();
Wakelock.enabled.then((value) => print('Wakelock:$value'));
final ratio =
MediaQuery.of(context).size.width / MediaQuery.of(context).size.height;

Expand All @@ -69,33 +72,43 @@ class _MobilePlayerState extends State<MobilePlayer> {
: (widget.type == 'bilibili'
? BilibiliDanmakuListView(roomId: widget.danmakuId)
: DouYuDanmakuListView(roomId: widget.danmakuId));
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context);
},
return WillPopScope(
onWillPop: () async {
_controller.pause();
Wakelock.disable();
Wakelock.enabled.then((value) => print('Wakelock:$value'));
return true;
},
child: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context);
Wakelock.disable();
Wakelock.enabled.then((value) => print('Wakelock:$value'));
},
),
title: Text(widget.title),
),
title: Text(widget.title),
body: ratio > 1.2
? Row(
children: <Widget>[
nativeVideo,
Expanded(
child: danmakuListView,
),
],
)
: Column(
children: <Widget>[
nativeVideo,
Expanded(
child: danmakuListView,
),
],
),
),
body: ratio > 1.2
? Row(
children: <Widget>[
nativeVideo,
Expanded(
child: danmakuListView,
),
],
)
: Column(
children: <Widget>[
nativeVideo,
Expanded(
child: danmakuListView,
),
],
),
);
}
}
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
html: ^0.15.0
http: ^0.13.4
shared_preferences: ^2.0.15
wakelock: ^0.6.2
dart_vlc:
git:
url: https://github.com/iiijam/dart_vlc.git
Expand Down

0 comments on commit b504070

Please sign in to comment.