Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


One button / command to load & play random track?
#1
I've been playing round for a few hours, but can't see an obvious way of doing this...

Starting state:

Radio stream sole item in playlist, paused.

Desired end state:

Two or three tracks loaded from the library at random (using the mpd auto-shuffle setting) and the 1st one playing.

At the moment I have to, from the starting state, go to the library, select any old song, clear/add, then go back to playback, hit random, click play etc

It would be nice to have a single command 'play_random.sh' which would achieve the above... I fear there is too much going on with the UI / database to have something scripted.

What do you think?
Reply
#2
Quick test and no issues on my end.

- Audio config: Turn Auto-shuffle on
- Library: Clear/play a single radio station
- Playback: click Play/Pause so item is paused
- Playback: click Random

Result:

2 random songs are queued and the first one is playing
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
Ahh, I think the activation of Random + some latency (Pi Zero) got me confused.

I agree, your workflow is as expected - with the clicking on Random starting playback.

And the reverse (going back to a single radio station) requires:

- Playback: click Random
- Library: Clear/play a single station

The key bit is deselecting Random I think.

Is there a way to control the state of Random from the command line? The reason being that I'd like a single physical button to push which starts the random playing of tracks, to go along with the physical button to play a single radio station.
Reply
#4
You can send commands via the Web API for example

Code:
MPD commands

http://moode/command/?cmd=random 1
http://moode/command/?cmd=random 0
http://moode/command/?cmd=play
http://moode/command/?cmd=pause
http://moode/command/?cmd=next
http://moode/command/?cmd=stop
.
.
Volume and mute

http://moode/command/?cmd=vol.sh up 1
http://moode/command/?cmd=vol.sh dn 1
http://moode/command/?cmd=vol.sh mute
http://moode/command/?cmd=vol.sh 12
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#5
(02-27-2019, 12:31 PM)Tim Curtis Wrote: You can send commands via the Web API for example

MPD commands

http://moode/command/?cmd=random 1
http://moode/command/?cmd=random 0

Yeah, that's what I tried. But it seems you can't switch off the "ashuffle random" using http://moode/command/?cmd=random 0

Code:
pi@moode-kitchen:~ $ mpc pause
Johann Strauss - The Blue Danube (Reprise)
[paused]  #1/2   0:07/8:21 (1%)
volume: 25%   repeat: off   random: on    single: off   consume: on
pi@moode-kitchen:~ $ mpc random 0
Johann Strauss - The Blue Danube (Reprise)
[paused]  #1/2   0:07/8:21 (1%)
volume: 25%   repeat: off   random: off   single: off   consume: on
pi@moode-kitchen:~ $ mpc clear && mpc load Radio4 && mpc play
volume: 25%   repeat: off   random: off   single: off   consume: on
loading: Radio4
The Coasters - Yakety Yak
[playing] #1/3   0:00/1:53 (0%)
volume: 25%   repeat: off   random: off   single: off   consume: on

E.g., I'm enjoying random music but want to listen to the news via radio streaming.

I'd issue "mpc clear && mpc load Radio4 && mpc play". However, this reloads the randomness and plays it, and the radio stream is loaded to the end of the playlist.

I guess the ashuffle is set via the GUI only? I notice in snd-config.php the mpd random is set to 0

Also, I noticed that with the ashuffle random activated, a restart of the device causes music to play once rebooted, despite the "autoplay after start" being off.
Reply
#6
The web API only accepts MPD commands, vol.sh commands and <script>.sh commands where <script> is a user written script stored in /var/www
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#7
(02-27-2019, 04:16 PM)Tim Curtis Wrote: The web API only accepts MPD commands, vol.sh commands and <script>.sh commands where <script> is a user written script stored in /var/www

Yeah, so I'm looking at ways to trigger what happens when I click on the random button, ie this code in scripts-panels.js:

Code:
 $('.btn-toggle').click(function(e) {
               var id = $(this).attr('id');
               var cmd = id.startsWith('m') ? id.substr(1) : id;
               var toggle = $(this).hasClass('btn-primary') ? '0' : '1';
               if (cmd == 'random' && SESSION.json['ashufflesvc'] == '1') {
                       var resp = sendMoodeCmd('GET', 'ashuffle', {'ashuffle':toggle}); // toggle ashuffle on/off
                   $('random').toggleClass('btn-primary');
                   $('consume').toggleClass('btn-primary');
                       sendMpdCmd('consume ' + toggle);
               }
               else {
                   $(this).toggleClass('btn-primary');
                       sendMpdCmd(cmd + ' ' + toggle);
               }
Which is where the limits of my expertise are exposed - never having touched JS before.

One (perhaps the easiest?) approach could be to use puppeteer on my control device to run a headless browser with the Moode playback panel open, and simulate the click when called.
Reply
#8
Code:
#!/usr/bin/python
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('no-sandbox') # so it can be run as root
driver = webdriver.Chrome(chrome_options=options)

driver.get('http://moode.local')

#a = driver.find_element_by_id("play")
b = driver.find_element_by_id("random")

#a.click()
b.click()

driver.close()

So this code is a really inefficient way of getting close to what I described. This will 'click' on the 'random' button on the web interface from a (headless) remote machine. It uses Selenium and Chromium / chromedriver to run the web page in the background so things can be interacted with.

I've taken this and incorporated in to my GPIO button interface code - and so far works as I had hoped allowing me to go from a radio stream to random play (using ashuffle) and back again. Happy to share that code if people are interested.

T
Reply
#9
@tristanc

Don't know where you and Tim will end up on this issue but thanks for sharing your code with the rest of us. Wasn't your intention, no doubt, but you've given ideas about a languishing project of my own. Somehow I missed the memo about Selenium Tongue

Regards,
Kent
Reply
#10
(03-03-2019, 02:33 PM)TheOldPresbyope Wrote: @tristanc

Don't know where you and Tim will end up on this issue but thanks for sharing your code with the rest of us. Wasn't your intention, no doubt, but you've given ideas about a languishing project of my own. Somehow I missed the memo about Selenium Tongue

Regards,
Kent

Glad to be of help! Also glad I looked in to Selenium - looks a really interesting tool for so many things, particularly where a web interface isn't 'open' or API-able.

T
Reply


Forum Jump: