video_player 按键监听
This commit is contained in:
parent
a88c9d6298
commit
1d621444fb
@ -55,8 +55,8 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
});
|
||||
}
|
||||
|
||||
void onKey(RawKeyEvent event){
|
||||
if(event is RawKeyUpEvent) return;
|
||||
void onKey(RawKeyEvent event) {
|
||||
if (event is RawKeyUpEvent) return;
|
||||
RawKeyEventDataAndroid e = event.data as RawKeyEventDataAndroid;
|
||||
switch (e.keyCode) {
|
||||
case 21:
|
||||
@ -68,7 +68,7 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
_controller!.seekTo(Duration(milliseconds: pos + 30000));
|
||||
break;
|
||||
case 62:
|
||||
if(_controller!.value.isPlaying){
|
||||
if (_controller!.value.isPlaying) {
|
||||
_controller!.pause();
|
||||
} else {
|
||||
_controller!.play();
|
||||
@ -80,7 +80,7 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
}
|
||||
|
||||
void fijkOnKey(RawKeyEvent event) {
|
||||
if(event is RawKeyUpEvent) return;
|
||||
if (event is RawKeyUpEvent) return;
|
||||
switch (event.character) {
|
||||
case ' ':
|
||||
if (player?.state == FijkState.paused) {
|
||||
@ -93,17 +93,17 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
switch ((event.data as RawKeyEventDataAndroid).keyCode) {
|
||||
case 22:
|
||||
// player!.pause().then((value) {
|
||||
int pos = min(player!.value.duration.inMilliseconds,
|
||||
player!.currentPos.inMilliseconds + 30000);
|
||||
player!.seekTo(pos).then((value) {
|
||||
if(_timer != null){
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(const Duration(milliseconds: 500), () {
|
||||
player!.start();
|
||||
_timer = null;
|
||||
});
|
||||
int pos = min(player!.value.duration.inMilliseconds,
|
||||
player!.currentPos.inMilliseconds + 30000);
|
||||
player!.seekTo(pos).then((value) {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(const Duration(milliseconds: 500), () {
|
||||
player!.start();
|
||||
_timer = null;
|
||||
});
|
||||
});
|
||||
// });
|
||||
break;
|
||||
}
|
||||
@ -114,22 +114,30 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 35,
|
||||
),
|
||||
// appBar: AppBar(
|
||||
// toolbarHeight: 35,
|
||||
// ),
|
||||
body: player == null
|
||||
? Center(
|
||||
child: _controller!.value.isInitialized
|
||||
? AspectRatio(
|
||||
aspectRatio: _controller!.value.aspectRatio,
|
||||
child: RawKeyboardListener(
|
||||
onKey: onKey,
|
||||
autofocus: true,
|
||||
focusNode: FocusNode(),
|
||||
child: VideoPlayer(_controller!),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
? PopScope(
|
||||
onPopInvoked: (val) {
|
||||
if (!val) {
|
||||
return;
|
||||
}
|
||||
_controller!.pause();
|
||||
},
|
||||
child: Center(
|
||||
child: _controller!.value.isInitialized
|
||||
? AspectRatio(
|
||||
aspectRatio: _controller!.value.aspectRatio,
|
||||
child: RawKeyboardListener(
|
||||
onKey: onKey,
|
||||
autofocus: true,
|
||||
focusNode: FocusNode(),
|
||||
child: VideoPlayer(_controller!),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
alignment: Alignment.center,
|
||||
@ -146,17 +154,15 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
focusNode: FocusNode(),
|
||||
autofocus: true,
|
||||
child: PopScope(
|
||||
onPopInvoked: (val){
|
||||
if(!val){
|
||||
onPopInvoked: (val) {
|
||||
if (!val) {
|
||||
return;
|
||||
}
|
||||
this.player?.exitFullScreen();
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
child: Stack(children: [
|
||||
defaultFijkPanelBuilder(
|
||||
player, data, context, viewSize, texturePos),
|
||||
|
||||
]),
|
||||
));
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user