mpv
mpv copied to clipboard
Is there any way to add touch swipe gestures to mpv?
mpv version and platform
Windows 10, The latest build from https://mpv.srsfckn.biz/
Reproduction steps
Open a video and try to swipe.
Expected behavior
Some navigation happens
Actual behavior
Nothing
I just want to know if there's a way to configure MPV to recognize swipe gestures for example swiping up and down to adjust the volume and swipe left and right to navigate forward and backward in the playback.
It's not possible out of the box. But it's not impossible, either. A user script has access to all of the information it would need to implement a gesture recognition system.
When you say user script, are you talking about input.conf? I have it configured along with mpv.conf but I can't find any info about mapping up touch gestures
No, I meant a lua script that tracks mouse movement and performs gesture recognition.
Oh. I have zero clue how to use that so I guess I'll just wait in case it ever gets approved and gets implemented in the future.
require 'mp.options'
local options = { step = 5, }
read_options(options,'touchscreen-seek')
function touch_seek() local pos = get_mouse_area() local step = options.step
if pos == 'left' then mp.commandv('seek', -1*step) elseif pos == 'right' then mp.commandv('seek', step) else toggle_fullscreen() end
end
function get_mouse_area() local mouse_x,mouse_y = mp.get_mouse_pos() local winX,winY = mp.get_property('osd-width'), mp.get_property('osd-height')
if mouse_x < winX/3 then return 'left' elseif mouse_x < winX/3*2 then return 'middle' else return 'right' end
end
function toggle_fullscreen() local screen_stat = mp.get_property('fullscreen')
if screen_stat == 'yes' then screen_stat = 'no' else screen_stat = 'yes' end
mp.set_property('fullscreen', screen_stat)
end
mp.add_key_binding(nil, "touchscreen-seek", touch_seek) mp.msg.info("Loaded touchscreen-seek Lua flavor")
require 'mp.options'
local options = { step = 5, }
read_options(options,'touchscreen-seek')
function touch_seek() local pos = get_mouse_area() local step = options.step
if pos == 'left' then mp.commandv('seek', -1*step) elseif pos == 'right' then mp.commandv('seek', step) else toggle_fullscreen() end
end
function get_mouse_area() local mouse_x,mouse_y = mp.get_mouse_pos() local winX,winY = mp.get_property('osd-width'), mp.get_property('osd-height')
if mouse_x < winX/3 then return 'left' elseif mouse_x < winX/3*2 then return 'middle' else return 'right' end
end
function toggle_fullscreen() local screen_stat = mp.get_property('fullscreen')
if screen_stat == 'yes' then screen_stat = 'no' else screen_stat = 'yes' end
mp.set_property('fullscreen', screen_stat)
end
mp.add_key_binding(nil, "touchscreen-seek", touch_seek) mp.msg.info("Loaded touchscreen-seek Lua flavor")
I have the same requirement to play on a Windows tablet. I wrote a script to support double tap to seek. Double tap on left to seek backward and on right to seek forward.
Copy and store as scripts/touchscreen-seek.lua
Step value can be defined in script-opts/touchscreen-seek.conf, the default value is 5s. step = 5
Define in input.conf MBTN_LEFT_DBL script-binding touchscreen-seek
Hope it can help you. @sprite-1
Hi, thanks @imufly for your script! I'm running mpv as video player in postmarketOS over a pinephone. I open every video already in fullscreen, so I found handy to have the middle double tap triggering a pause/resume toggle.
Instead of calling toggle_fullscreen() in the else branch of touch_seek() , I call the function toggle_pause(). The code:
function toggle_pause()
local pause = mp.get_property_native("pause")
mp.set_property_native("pause", not pause)
end
A user script has access to all of the information it would need to implement a gesture recognition system.
Is there a way to distinguish between mouse and touchscreen events, or handle multiple fingers?
Looking at the OSC source code, it handles mouse events through input events like MOUSE_BTN* and MOUSE_MOVE. Currently there are no separate input keys for touch events, but the same mouse events are sent for touches as well.
In order to be able to properly handle touchscreen gestures from Lua scripts, we would need:
- A way to distinguish between mouse and touch events. For instance, mouse dragging should continue to drag the window, while touch swipes may be used to seek or change the volume.
- Access the number and location of fingers in the event handler.
A conventional way to implement this is to send separate events for touches (perhaps even depending on the number of fingers). Probably mouse events should also be sent so as not to break legacy configurations. Touch event handlers should be able to say whether to suppress the synthesized mouse events.
A simpler way would be to always send mouse events, but have a way for the event handler to access whether the event was actually generated by a mouse or a touchscreen, and in the latter case access the number and position of the fingers.
Found a user script that does something similar and wanted to share it here: https://github.com/omeryagmurlu/mpv-gestures
Is there a way to distinguish between mouse and touchscreen events, or handle multiple fingers?
https://github.com/mpv-player/mpv/pull/14003