【问题标题】:Hotkeys ignored w Python libvlc bindings on Linux热键忽略了 Linux 上的 Python libvlc 绑定
【发布时间】:2021-09-28 07:07:15
【问题描述】:

我在 Linux 上使用 python-vlc 绑定控制来自 Python 3.x 的视频时遇到问题。 视频在窗口中播放良好,但热键似乎被忽略了。 libvlc 媒体播放器是否处理热键?

我的最小代码:

import vlc
from time import sleep


player = vlc.MediaPlayer("test.mp4")
player.video_set_key_input(True)
player.play()
while player.get_state()!=vlc.State.Ended:
    sleep(1)

【问题讨论】:

  • 简而言之:不!在 vlc.py 的代码底部查找内置播放器,特别是 keybindings 字典并注意 import / getch 的定义。另一种选择是将代码包装在 GUI 中并在那里处理键输入。
  • @RolfofSaxony 所以 video_set_key_input() 只是一个骗局。还是谢谢。
  • 显然,如果您知道得更好:A)为什么要问这个问题,B)为什么不发布一个答案,向其他人展示有类似问题的解决方法。 SO 不是竞赛,人们会尽其所知发布答案和 cmets。
  • @RolfofSaxony 我还没有找到答案。 video_set_key_input() 的文档字符串指出:“由于历史原因,默认情况下,键盘事件由 LibVLC 视频小部件处理。”然而似乎并非如此。

标签: python python-3.x libvlc


【解决方案1】:

我认为您的论点,即 video_set_key_inputvideo_set_mouse_input 是解决方案是对这些功能的误解。

来自vlc.py

def video_set_key_input(self, on):
    '''Enable or disable key press events handling, according to the LibVLC hotkeys
    configuration. By default and for historical reasons, keyboard events are
    handled by the LibVLC video widget.
    @note: On X11, there can be only one subscriber for key press and mouse
    click events per window. If your application has subscribed to those events
    for the X window ID of the video widget, then LibVLC will not be able to
    handle key presses and mouse clicks in any case.
    @warning: This function is only implemented for X11 and Win32 at the moment.
    @param on: true to handle key press events, false to ignore them.
    '''
    return libvlc_video_set_key_input(self, on)


def video_set_mouse_input(self, on):
    '''Enable or disable mouse click events handling. By default, those events are
    handled. This is needed for DVD menus to work, as well as a few video
    filters such as "puzzle".
    See L{video_set_key_input}().
    @warning: This function is only implemented for X11 and Win32 at the moment.
    @param on: true to handle mouse click events, false to ignore them.
    '''
    return libvlc_video_set_mouse_input(self, on)

这表明将这些函数设置为False 只是告诉vlc 鼠标和键输入将被忽略并传递给用户应用程序。
为此,您的应用程序必须接受并处理来自指定 X 窗口的鼠标和键输入。

不是,突然按下空格键会暂停视频,就像vlc正在执行accepting and processing鼠标和键输入的任务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-07
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    • 2019-12-20
    相关资源
    最近更新 更多