Button Next prev music
Button Next prev music
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?
You do not have the required permissions to view the files attached to this post.
Re: Button Next prev music
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
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
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);https://github.com/wiboma/hudiy/blob/ma ... proto#L630
https://github.com/wiboma/hudiy/blob/ma ... Strokes.py
Hudiy Team
Re: Button Next prev music
Ok, I understood how the API works, thanks!
pozdrawiam
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);
});