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

Restart playback with space key binding #291

Closed
Keith94 opened this issue Jan 1, 2025 · 12 comments
Closed

Restart playback with space key binding #291

Keith94 opened this issue Jan 1, 2025 · 12 comments
Labels
question Questions relating to ModernZ osc or its configuration

Comments

@Keith94
Copy link
Contributor

Keith94 commented Jan 1, 2025

Expected behavior of the wanted feature

I was looking for a simple way to bind space to restart playback when end of file is reached, same way that YouTube does it.

control.lua can achieve this, for example with space script-binding control/cycle-pause, but it contains lots of extra stuff.

If there's enough interest maybe this feature can be added in directly to ModernZ, or optionally under a wiki page.

@Keith94 Keith94 added the feature request New feature or request label Jan 1, 2025
@Samillion
Copy link
Owner

Try

#input.conf
SPACE    seek 0 absolute; cycle pause

@Keith94
Copy link
Contributor Author

Keith94 commented Jan 1, 2025

The only problem with that is pressing space will always go back to beginning (even in the middle of playback) so it's not ideal.

@Samillion
Copy link
Owner

I think I misunderstood. I still don't quite understand, you said:

a simple way to bind space to restart playback when end of file is reached

That's from the beginning, right?

If you meant to do it automatically, you can use the loop button. Again, sorry if I'm misunderstanding the request.

@Samillion
Copy link
Owner

Samillion commented Jan 1, 2025

Did you mean you want to assign the keybind automatically at end of playback otherwise the keybind is normal?

You can add this as a script: ie: myplayback.lua

mp.observe_property("eof-reached", "bool", function(_, val)
    if val then
        mp.set_key_bindings({
           {"SPACE", function() mp.command("seek 0 absolute; cycle pause") end}
        }, "my-playback-restart", "force")
        
        mp.enable_key_bindings("my-playback-restart")
    else
        mp.disable_key_bindings("my-playback-restart")
    end
end)

@Keith94
Copy link
Contributor Author

Keith94 commented Jan 1, 2025

You can add this as a script: ie: myplayback.lua

Perfect ! That's exactly what I was looking for. Thank you so much

@Samillion
Copy link
Owner

You are very welcome, and happy new year! 🥳

@Keith94
Copy link
Contributor Author

Keith94 commented Jan 1, 2025

Happy New Year & ty for all the support. 👍🏻

@Keith94 Keith94 closed this as completed Jan 1, 2025
@Samillion Samillion added question Questions relating to ModernZ osc or its configuration and removed feature request New feature or request labels Jan 1, 2025
@Keith94
Copy link
Contributor Author

Keith94 commented Jan 6, 2025

Sam, I want MBTN_LEFT to do the same thing as SPACE in your code. How can I add MBTN_LEFT properly?

@Samillion
Copy link
Owner

Try:

mp.observe_property("eof-reached", "bool", function(_, val)
    if val then
        mp.set_key_bindings({
           {"SPACE", function() mp.command("seek 0 absolute; cycle pause") end},
           {"MBTN_LEFT", function() mp.command("seek 0 absolute; cycle pause") end},
        }, "my-playback-restart", "force")
        
        mp.enable_key_bindings("my-playback-restart")
    else
        mp.disable_key_bindings("my-playback-restart")
    end
end)

But this conflicts with pause-indicator-lite I think, let me know. I can disable the indicator keybind on end of file or make it an option.

@Keith94
Copy link
Contributor Author

Keith94 commented Jan 6, 2025

Great, It's working perfectly. Thanks. You're right about the conflict, though.

@Samillion
Copy link
Owner

Samillion commented Jan 6, 2025

Updated pause-indicator-lite, should be fine now in default behavior.

keybind_eof_disable is enabled by default.

@Keith94
Copy link
Contributor Author

Keith94 commented Jan 6, 2025

Very quick work. Thanks Sam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions relating to ModernZ osc or its configuration
Projects
None yet
Development

No branches or pull requests

2 participants