Button Next prev music

Post Reply
Sebix
Posts: 3
Joined: Wed Aug 05, 2026 8:15 am

Button Next prev music

Post 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
You do not have the required permissions to view the files attached to this post.
hudiy
Site Admin
Posts: 642
Joined: Mon Jul 14, 2025 7:42 pm

Re: Button Next prev music

Post 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
Hudiy Team
Sebix
Posts: 3
Joined: Wed Aug 05, 2026 8:15 am

Re: Button Next prev music

Post 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);
        });
Post Reply