Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure seek bar to use bottom bar OSD #124

Closed
jakeogh opened this issue Jul 19, 2020 · 7 comments
Closed

Configure seek bar to use bottom bar OSD #124

jakeogh opened this issue Jul 19, 2020 · 7 comments

Comments

@jakeogh
Copy link

jakeogh commented Jul 19, 2020

I'm trying to make the LEFT/RIGHT seek bar use the nice new bottom bar OSD/OSC(?). This example has the bottom bar if it's moused-over, but hitting LEFT/RIGHT draws the seek bar in the middle of the video instead of using the bottombar. Using git-latest.

#!/usr/bin/env python3

import sys
import mpv


def logger(loglevel, component, message):
    print('[{}] {}: {}'.format(loglevel, component, message), file=sys.stderr)


def play(media):
    print("play('{}')".format(media), file=sys.stderr)

    player = mpv.MPV(ytdl=True,
                     log_handler=logger,
                     input_default_bindings=True,
                     input_vo_keyboard=True,
                     terminal=True,
                     input_terminal=True,
                     script_opts='osc-layout=bottombar,osc-seekbarstyle=bar',
                     osc=True)

    player.on_key_press('ESC')(player.quit)
    player.on_key_press('ENTER')(lambda: player.playlist_next(mode='force'))

    try:
        for item in media:
            player.play(item)
            player.wait_for_playback()
    except mpv.ShutdownError:
        pass

    player.terminate()

if __name__ == '__main__':
    play(media=['test.mkv'])
@jakeogh jakeogh changed the title Get seek bar to use the bottom bar OSD Configure seek bar to use bottom bar OSD Jul 19, 2020
@jaseg
Copy link
Owner

jaseg commented Jul 19, 2020

What you're asking for is a known issue in mpv [1], [2]. I found an only slightly hacky workaround until this gets fixed upstream:

#!/usr/bin/env python3

import sys
import mpv


def logger(loglevel, component, message):
    print('[{}] {}: {}'.format(loglevel, component, message), file=sys.stderr)


def play(media):
    print("play('{}')".format(media), file=sys.stderr)

    player = mpv.MPV(ytdl=True,
                     log_handler=logger,
                     input_default_bindings=True,
                     input_vo_keyboard=True,
                     terminal=True,
                     input_terminal=True,
                     osd_bar=False,
                     scripts='test.lua'
                     )

    player.on_key_press('ESC')(player.quit)
    player.on_key_press('ENTER')(lambda: player.playlist_next(mode='force'))

    try:
        for item in media:
            player.play(item)
            player.wait_for_playback()
    except mpv.ShutdownError:
        pass

    player.terminate()

if __name__ == '__main__':
    play(media=['LGR Plays - Goat Simulator-j4HY_fxwiZo.mp4'])

Put this lua script in the current working directory or somewhere else mpv can find it:

-- emulate require() path search but load into current scope instead.
-- osc.lua does not export a module table, so require would just return True.
for key, loader in pairs(package.loaders) do
    res = loader('@osc.lua')
    print('res value', '"', res, '"', type(res))
    if type(res) == 'function' then
        print('found', res, res('@osc.lua'))
        break
    end
end

function seek_handler()
    show_osc()
end
mp.register_event("seek", seek_handler)

@jaseg
Copy link
Owner

jaseg commented Jul 19, 2020

To expand on this: The thing on the bottom is the "on-screen controller" (osc) and is drawn from mpv's included "osc.lua" script. The bar in the middle is part of the "on-screen display" (osd) and is drawn from mpv's core C code. Both are functionally independent pieces of code. What the above code does is it loads the built-in "osc.lua" script and patches in another event listener that will show it on seeks, automatically hiding it like with mouse movements.

@jakeogh
Copy link
Author

jakeogh commented Jul 19, 2020

Beautiful. That works perfect.

@jakeogh jakeogh closed this as completed Jul 19, 2020
@pbaykalov
Copy link

pbaykalov commented Nov 2, 2020

@jaseg can you please tell somewhat more about how this scrpit should be used? I do not use Python MPV but I was searching for the solution of this annoying property of MPV and found this issue. Putting osc.lua into a folder as described by MPV manual was not enough.

@AndydeCleyre
Copy link

@pbaykalov I have saved that lua script as ~/.config/mpv/scripts/osc_on_seek.lua, and that's enough for me. Is it any different if you pass the script as an option?

$ mpv --script=~/.config/mpv/scripts/osc_on_seek.lua /path/to/video/file

@jaseg
Copy link
Owner

jaseg commented Nov 5, 2020

@pbaykalov If you are using mpv from the command-line as opposed to as a library, saving it to your user scripts as @AndydeCleyre wrote is the way to go.

edit: Just in case, "the script" here is not osc.lua, but the second code block above. That code block loads and modifies mpv's own osc.lua.

@AndydeCleyre The reason I passed the script as an option in the code example is that when you use mpv as a library, you would not want to install this kind of script into a user's config. Instead, it would have to be kept as part of your program, and --script is a good way to do that.

@pbaykalov
Copy link

pbaykalov commented Mar 16, 2023

What you're asking for is a known issue in mpv [1], [2]. I found an only slightly hacky workaround until this gets fixed upstream:

#!/usr/bin/env python3

import sys
import mpv


def logger(loglevel, component, message):
    print('[{}] {}: {}'.format(loglevel, component, message), file=sys.stderr)


def play(media):
    print("play('{}')".format(media), file=sys.stderr)

    player = mpv.MPV(ytdl=True,
                     log_handler=logger,
                     input_default_bindings=True,
                     input_vo_keyboard=True,
                     terminal=True,
                     input_terminal=True,
                     osd_bar=False,
                     scripts='test.lua'
                     )

    player.on_key_press('ESC')(player.quit)
    player.on_key_press('ENTER')(lambda: player.playlist_next(mode='force'))

    try:
        for item in media:
            player.play(item)
            player.wait_for_playback()
    except mpv.ShutdownError:
        pass

    player.terminate()

if __name__ == '__main__':
    play(media=['LGR Plays - Goat Simulator-j4HY_fxwiZo.mp4'])

Put this lua script in the current working directory or somewhere else mpv can find it:

-- emulate require() path search but load into current scope instead.
-- osc.lua does not export a module table, so require would just return True.
for key, loader in pairs(package.loaders) do
    res = loader('@osc.lua')
    print('res value', '"', res, '"', type(res))
    if type(res) == 'function' then
        print('found', res, res('@osc.lua'))
        break
    end
end

function seek_handler()
    show_osc()
end
mp.register_event("seek", seek_handler)

The Lua script you suggested seeems to always break the controls in pseudo-GUI in weird way: it stops accepting mouse clicks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants