Page 1 of 1

Button Next prev music

Posted: Sat Aug 15, 2026 6:19 pm
by Sebix
Hi, I need next song and previous song buttons. I used the example from GitHub media.html. It retrieved the author and title perfectly, but I'm struggling to add the next and previous, play, pause buttons in JavaScript. Can you help?
7GkLpQpB.jpg

Re: Button Next prev music

Posted: Sat Aug 15, 2026 6:55 pm
by hudiy
To control playback, you can use the DispatchAction message from the API and the appropriate actions (now_playing_next_track, now_playing_previous_track, now_playing_toggle_play, now_playing_pause, now_playing_play, now_playing_go_to_player): https://github.com/wiboma/hudiy/blob/ma ... ed-actions

An example of how to use DispatchAction in JavaScript can be found e.g. in the file:

https://github.com/wiboma/hudiy/blob/ma ... k.html#L62

Code: Select all

hudiy.api.DispatchAction = hudiy.api.protoRoot.lookupType("hudiy.app.api.DispatchAction");
const msg = hudiy.api.DispatchAction.create({
action: "now_playing_next_track"
});
const payload = hudiy.api.DispatchAction.encode(msg).finish();
hudiy.api.client.sendMessage(hudiy.api.MessageType.MESSAGE_DISPATCH_ACTION, 0, payload);
Another option is to simulate keystrokes, also via the API:

https://github.com/wiboma/hudiy/blob/ma ... proto#L630
https://github.com/wiboma/hudiy/blob/ma ... Strokes.py

Re: Button Next prev music

Posted: Sun Aug 16, 2026 9:42 am
by Sebix
Ok, I understood how the API works, thanks!

pozdrawiam

Code: Select all

		hudiy.api.DispatchAction = hudiy.api.protoRoot.lookupType("hudiy.app.api.DispatchAction");
		
		const prevMusic = document.querySelector('.prevMusic');
		const playMusic = document.querySelector('.playMusic');
		const nextMusic = document.querySelector('.nextMusic');
		
        prevMusic.addEventListener("click", () => {
            const msg = hudiy.api.DispatchAction.create({
                action: "now_playing_previous_track"
            });
            const payload = hudiy.api.DispatchAction.encode(msg).finish();
            hudiy.api.client.sendMessage(hudiy.api.MessageType.MESSAGE_DISPATCH_ACTION, 0, payload);
        });

        playMusic.addEventListener("click", () => {
            const msg = hudiy.api.DispatchAction.create({
                action: "now_playing_toggle_play"
            });
            const payload = hudiy.api.DispatchAction.encode(msg).finish();
            hudiy.api.client.sendMessage(hudiy.api.MessageType.MESSAGE_DISPATCH_ACTION, 0, payload);
        });

        nextMusic.addEventListener("click", () => {
            const msg = hudiy.api.DispatchAction.create({
                action: "now_playing_next_track"
            });
            const payload = hudiy.api.DispatchAction.encode(msg).finish();
            hudiy.api.client.sendMessage(hudiy.api.MessageType.MESSAGE_DISPATCH_ACTION, 0, payload);
        });