Skip to content

Key-binding does not work. #106

Description

@wangjianyuan10

I just try the demo given on my mac,the music is playing but key-binding does not work.
How to work it out?

coding=utf-8

#!/usr/bin/env python3
import mpv
import sys

def my_log(loglevel, component, message):
print('[{}] {}: {}'.format(loglevel, component, message))

player = mpv.MPV(log_handler=my_log,
input_default_bindings=True,
input_vo_keyboard=True,
ytdl=True)

Property access, these can be changed at runtime

@player.property_observer('time-pos')
def time_observer(_name, value):
# Here, _value is either None if nothing is playing or a float containing
# fractional seconds since the beginning of the file.
str1 = 'Now playing at {:.2f}s'.format(value)
print(str1, end='\n')
sys.stdout.flush()
print('\b'*(len(str1)+1), end='')

player.fullscreen = True
player.loop_playlist = 'inf'

Option access, in general these require the core to reinitialize

player['vo'] = 'gpu'

@player.on_key_press('q')
def my_q_binding():
print('THERE IS NO ESCAPE')
sys.exit(0)

@player.on_key_press('s')
def my_s_binding():
pillow_img = player.screenshot_raw()
pillow_img.save('screenshot.png')

player.play('/Users/mac/Music/41973.mp3')
player.wait_for_playback()

del player

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions