jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
547 stars 68 forks source link

Key-binding does not work. #106

Closed wangjianyuan10 closed 4 years ago

wangjianyuan10 commented 4 years ago

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

McSinyx commented 4 years ago

Please reformat in Markdown so we can read it easilier, e.g.

```python
# your code
```
jakeogh commented 4 years ago

see #122 for a working keybinding example

jaseg commented 4 years ago

I think your question should be answered in #122.