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