video_player 按键监听
This commit is contained in:
parent
6b1b409317
commit
a88c9d6298
@ -29,8 +29,8 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
SystemChrome.setPreferredOrientations(
|
||||
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
|
||||
|
||||
// initVideoPlayer();
|
||||
initFijkPlayer();
|
||||
initVideoPlayer();
|
||||
// initFijkPlayer();
|
||||
}
|
||||
|
||||
void initVideoPlayer() {
|
||||
@ -55,7 +55,32 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
});
|
||||
}
|
||||
|
||||
void onKey(RawKeyEvent event) {
|
||||
void onKey(RawKeyEvent event){
|
||||
if(event is RawKeyUpEvent) return;
|
||||
RawKeyEventDataAndroid e = event.data as RawKeyEventDataAndroid;
|
||||
switch (e.keyCode) {
|
||||
case 21:
|
||||
int pos = _controller!.value.position.inMilliseconds;
|
||||
_controller!.seekTo(Duration(milliseconds: pos - 30000));
|
||||
break;
|
||||
case 22:
|
||||
int pos = _controller!.value.position.inMilliseconds;
|
||||
_controller!.seekTo(Duration(milliseconds: pos + 30000));
|
||||
break;
|
||||
case 62:
|
||||
if(_controller!.value.isPlaying){
|
||||
_controller!.pause();
|
||||
} else {
|
||||
_controller!.play();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
debugPrint("$e");
|
||||
}
|
||||
}
|
||||
|
||||
void fijkOnKey(RawKeyEvent event) {
|
||||
if(event is RawKeyUpEvent) return;
|
||||
switch (event.character) {
|
||||
case ' ':
|
||||
if (player?.state == FijkState.paused) {
|
||||
@ -69,7 +94,7 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
case 22:
|
||||
// player!.pause().then((value) {
|
||||
int pos = min(player!.value.duration.inMilliseconds,
|
||||
player!.currentPos.inMilliseconds + 10000);
|
||||
player!.currentPos.inMilliseconds + 30000);
|
||||
player!.seekTo(pos).then((value) {
|
||||
if(_timer != null){
|
||||
_timer!.cancel();
|
||||
@ -97,14 +122,19 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
child: _controller!.value.isInitialized
|
||||
? AspectRatio(
|
||||
aspectRatio: _controller!.value.aspectRatio,
|
||||
child: VideoPlayer(_controller!),
|
||||
child: RawKeyboardListener(
|
||||
onKey: onKey,
|
||||
autofocus: true,
|
||||
focusNode: FocusNode(),
|
||||
child: VideoPlayer(_controller!),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
)
|
||||
: Container(
|
||||
alignment: Alignment.center,
|
||||
child: RawKeyboardListener(
|
||||
onKey: onKey,
|
||||
onKey: fijkOnKey,
|
||||
focusNode: FocusNode(),
|
||||
autofocus: true,
|
||||
child: FijkView(
|
||||
@ -112,7 +142,7 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
|
||||
panelBuilder: (FijkPlayer player, FijkData data,
|
||||
BuildContext context, Size viewSize, Rect texturePos) {
|
||||
return RawKeyboardListener(
|
||||
onKey: onKey,
|
||||
onKey: fijkOnKey,
|
||||
focusNode: FocusNode(),
|
||||
autofocus: true,
|
||||
child: PopScope(
|
||||
|
Loading…
Reference in New Issue
Block a user