Random choise mp3 playlist

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Random choise mp3 playlist

#1 Post by Dick60 » 01 May 2021, 08:01

I use the PFplayer mini on my ESP8266 device with the latest rom.It works great but is there a a rule to start playing the playlist like a Lucky shot, so not sequently but randomly?

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#2 Post by TD-er » 01 May 2021, 09:38

We don't have a random function (which is a great feature by the way), but you could create one in the rules.

What you could do, is use the RSSI as random generator and multiply it by the uptime.

Let's assume you have the current track nr stored in variable #1 and number of tracks in variable #2
In this example I will store the random number in variable #3.

Code: Select all

let,3,abs(%rssi%) * %uptime%
let,1,([int#3]*[int#1])%[int#2]
With this code your next track nr is in variable #1 (to be used in rules with [int#1])

(untested code)

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#3 Post by Ath » 01 May 2021, 09:57

Looking at the commands for the DFR-0299, there is a command available to get random playback, it just isn't available to be set.
And the same goes for 'repeat', AFAICS, which would probably be useful here as well.

Wouldn't be too hard to add, except I don't have such unit available, so actual testing would have to be done by you or someone else. What type and flash configuration (.bin file name is helpful) do you use?
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#4 Post by Ath » 01 May 2021, 11:34

Dick60 wrote: 01 May 2021, 08:01 I use the PFplayer mini on my ESP8266 device with the latest rom.It works great but is there a a rule to start playing the playlist like a Lucky shot, so not sequently but randomly?
I've opened a pull request (PR #3615) adding a mode and a repeat command.

This plugin is only available in the 'test' .bin files, but as they are currently too big, they won't be available in the PR builds. (There's a separate PR #3600 to try and solve that).

I can provide you with an (adapted) 'test' build if you provide the type you need, and a list of other plugins that must be available too (if any), as I have to leave some out to create a working build.

Based on your highly appreciated feedback we can opt to actually include it in ESPEasy.
/Ton (PayPal.me)

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#5 Post by Dick60 » 01 May 2021, 12:19

thanks for the explanation. At the moment I use the test.bin because that was the only bin where the MP3 player was available. What i need in my project is the mp3 player and some normal switches. I appreciate the offer, to make an costum test.bin for me. After a succesfull implementation I can give you feedback of my findings.

I hope you have enough info to create the test.bin.

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#6 Post by Ath » 01 May 2021, 16:35

Dick60 wrote: 01 May 2021, 12:19 At the moment I use the test.bin because that was the only bin where the MP3 player was available. What i need in my project is the mp3 player and some normal switches. I appreciate the offer, to make an costum test.bin for me. After a succesfull implementation I can give you feedback of my findings.
Here's a test-build (attached below) with the new commands included.

From the (also updated) documentation:
Screenshot - 01_05_2021 , 16_33_37.png
Screenshot - 01_05_2021 , 16_33_37.png (35.05 KiB) Viewed 18769 times
Attachments
ESP_Easy_mega_20210501_test_ESP8266_4M1M.zip
(653.18 KiB) Downloaded 392 times
/Ton (PayPal.me)

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#7 Post by Dick60 » 02 May 2021, 10:03

I hope, there is no misunderstanding from my side, I have load the attached Bin on my NodeMcu without any problems, created the device DFPLAYER-MINI and tested the play mode (http://xxx.xxx.x.xx/control?cmd=play,3). Worked perfect. Tried the new option MODE at boot

Code: Select all

 On System#Boot do 
   vol,10
   mode,3
   delay,180 //play the song for 30 seconds (this is a generic command!)
   stop
 endon
Did not work. Tried http://xxx.xxx.x.xx/control?cmd=mode,3 in my IE, Did not work.
Any idea? What am I doing wrong?

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#8 Post by Ath » 02 May 2021, 13:40

Not sure if you are doing anything wrong, there are a lot of possible causes here

- You can enter the commands, as shown in the documentation above, on the Tools page, no prefix like control?cmd= etc needed there, and the quickest way to test a command
- Calling that type of commands from the System#Boot event might be a bit 'early', not sure if the plugin is already fully initialized at that point (though I'd expect it would be). Adding a delay like you did is a big no-no, so that's why I updated the example code, see below.
- I have no player module available, so I've been unable to do any testing at all, just extended the existing command structure
- Chinese clones are not necessarily 100% compatible with the original player, so they can have a chip that doesn't support these commands, don't know what exact type of module you are using

Updated Rules example (as available in the updated documentation):

Code: Select all

On System#Boot do
  vol,10
  play,255 // file number 255
  timerSet,1,30 //play the song for 30 seconds (this is a generic command!)
Endon

On Rules#Timer=1 do
  Stop
Endon
/Ton (PayPal.me)

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#9 Post by Dick60 » 02 May 2021, 14:50

I've tested the new command MODE as described in your previous answere. The PLAY option is working but the MODE,3 without the "control?cmd=" (http://xxx.xxx.x.xx/mode,3) is not working for now. Probably I have to wait for the final version of the plug-in.

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#10 Post by TD-er » 02 May 2021, 15:27

Dick60 wrote: 02 May 2021, 14:50 I've tested the new command MODE as described in your previous answere. The PLAY option is working but the MODE,3 without the "control?cmd=" (http://xxx.xxx.x.xx/mode,3) is not working for now. Probably I have to wait for the final version of the plug-in.
You always need to include a command prefix as you tried first.

Can you try sending the command in the "command" input field on the Tools page?
If you submit the command you will see some output, which may also state if it is an unknown command.
To be honest, I do find it a bit too generic, so maybe it conflicts with some other plugin?

You can also add the "task prefix" to the command to make sure you address it to the task you want to control.
See: https://espeasy.readthedocs.io/en/lates ... f-a-plugin

Also if you submitted the command there, the browser will reload with the command encoded in a new URL in the browser URL bar, so you can use that later on other devices.

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#11 Post by Dick60 » 02 May 2021, 16:05

this is all above my level of knowledge. Probably I use Variables for now to monitor the mp3's already played and that the new play not start Always with the same mp3. This is part of my alarm system (barking dog) and you do not want to start with the same mp3 but "randomly".

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#12 Post by Ath » 02 May 2021, 16:42

I will order a MP3-player module from my friends at Ali, but delivery will take a couple of weeks, so any testing by me will be postponed until then.
/Ton (PayPal.me)

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#13 Post by Dick60 » 02 May 2021, 16:47

thank you for the effort. I appreciate it.

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#14 Post by Dick60 » 17 Jun 2021, 21:32

The MP3 is working perfectly using the "normal control options mentioned in the WIKI. A nice, missing function, would be the option to put the volume and the Play number in a rule. Bur for now I m happy with it and thiefs are welcome with the sound of barking agressieve dogs. :lol:

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#15 Post by Ath » 06 Aug 2021, 21:28

Dick60 wrote: 02 May 2021, 14:50 I've tested the new command MODE as described in your previous answere. The PLAY option is working but the MODE,3 without the "control?cmd=" (http://xxx.xxx.x.xx/mode,3) is not working for now. Probably I have to wait for the final version of the plug-in.
Today I did some further investigation, but the limitation here seems to be in the chips/modules, not related to the plugin. They just don't conform to the documentation of the DFPlayer module, and that mode command just doesn't do what the documentation prescribes.
I've put a note in the documentation, and declared the work on the PR as completed.
The 'repeat' command is working as expected (when executed, plays all mp3's from first to last, then starts at the first again).
Now we wait for that PR (#3615) to be merged in ESPEasy.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#16 Post by TD-er » 06 Aug 2021, 23:12

It has been merged

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#17 Post by Dick60 » 07 Aug 2021, 21:07

Perhaps a stupid remark, is it ready for testing? Is the option for volume level, mentioned before not possible using rules?

Code: Select all

On System#Boot do
  [u][b]vol,10[/b][/u]
  play,255 // file number 255
  timerSet,1,30 //play the song for 30 seconds (this is a generic command!)
Endon

On Rules#Timer=1 do
  Stop
Endon

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#18 Post by Ath » 07 Aug 2021, 21:41

AFAICS, the 'vol,<volume>' command should work as intended, or did I misunderstand your question?

That command uses exacty the same function call as the initial volume, settable in the configuration.
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#19 Post by Ath » 07 Aug 2021, 21:48

Here's the latest build from the Github Actions download: (same .bin I posted earlier)
ESPEasy_normal_ESP8266_4M1M.zip
(2.26 MiB) Downloaded 408 times
/Ton (PayPal.me)

TyraNoah
New user
Posts: 2
Joined: 23 May 2021, 01:09

Re: Random choise mp3 playlist

#20 Post by TyraNoah » 09 Aug 2021, 20:32

Quite a lot that I really overlooked! That is helpful!

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#21 Post by Dick60 » 10 Aug 2021, 09:25

I am sorry, I don't understand, which BIN do i need to load to test the results?

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#22 Post by Ath » 10 Aug 2021, 09:30

You can download a .bin (in a .zip file) from post #19, above. Assuming that fits your ESP. If you need another type of build, just name it, and I'll put it here for download too.
/Ton (PayPal.me)

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#23 Post by Dick60 » 10 Aug 2021, 12:40

That is what I did, copied it in the latest release (20210802) bin folder, strted the flasher and selected the .bin you send to me. Finished succefull but as soon as I want to add the MP3 device, it is not in the list. Any idea or what am I doing wrong.

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#24 Post by Ath » 10 Aug 2021, 12:57

Check on the Info page (or the site footer) what .bin file you are using, it is in the 'test' builds. Looks like I posted the wrong .bin file :oops:
The improvements aren't included in the release build yet, so I'll post a test build asap.
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#25 Post by Ath » 10 Aug 2021, 13:12

A bin that does actually include the updated DFPlayer MP3 plugin:
(based on today's 'mega' branch, as the improvements have already been merged, but are not released yet)
ESP_Easy_mega_20210810_test_A_ESP8266_4M1M.zip
(626.14 KiB) Downloaded 432 times
/Ton (PayPal.me)

Dick60
Normal user
Posts: 244
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Random choise mp3 playlist

#26 Post by Dick60 » 11 Aug 2021, 15:09

I tested it and it works as expected. Thanks for the very very good service you delivered. :D

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#27 Post by Ath » 11 Aug 2021, 15:28

Glad to help ;)
/Ton (PayPal.me)

Sminter4
Normal user
Posts: 40
Joined: 04 Aug 2021, 23:25
Location: DE

Re: Random choise mp3 playlist

#28 Post by Sminter4 » 28 Apr 2025, 22:24

I'm also looking for a random number, but one that's plugin-independent and has the option to restrict it between a min and max value.

A function like this would be cool: let,<var nr>,rnd,<min>,<max>

Is this or something similar possible?

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#29 Post by Ath » 28 Apr 2025, 23:21

It would then be something like:

Code: Select all

let,random,%c_random%(%v_min%,%v_max%)
Or in old-style notation:

Code: Select all

let,1,%c_random%(1,100)
Note: The conversion %c_random%(min,max) doesn't yet exist!
/Ton (PayPal.me)

Sminter4
Normal user
Posts: 40
Joined: 04 Aug 2021, 23:25
Location: DE

Re: Random choise mp3 playlist

#30 Post by Sminter4 » 29 Apr 2025, 10:42

Is such a function feasible?
And if so, when?

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#31 Post by TD-er » 29 Apr 2025, 11:26

We're very close to making a new official release and this will not really affect existing code.
So I think we can include it as it is a nice feature to have.

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#32 Post by TD-er » 29 Apr 2025, 12:40

Added the feature, it will be included in the next upcoming build, which will very likely be in April this year :)

Sminter4
Normal user
Posts: 40
Joined: 04 Aug 2021, 23:25
Location: DE

Re: Random choise mp3 playlist

#33 Post by Sminter4 » 29 Apr 2025, 14:53

Wow - you guys are awesome! 😀
I've developed a new feature so quickly on the side.
I'm looking forward to testing it! I urgently need it for my new project...

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#34 Post by TD-er » 29 Apr 2025, 15:07

What build binary do you need, so I can make a test build for you to test it.
Will nearly be the same as the upcoming release build

Sminter4
Normal user
Posts: 40
Joined: 04 Aug 2021, 23:25
Location: DE

Re: Random choise mp3 playlist

#35 Post by Sminter4 » 29 Apr 2025, 17:18

Gladly. I need the normal_ESP8266_4M1M build.

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#36 Post by TD-er » 29 Apr 2025, 18:13

Sminter4 wrote: 29 Apr 2025, 17:18 Gladly. I need the normal_ESP8266_4M1M build.
Can you test this: https://www.dropbox.com/scl/fi/16l5544t ... u5xvz&dl=0

Sminter4
Normal user
Posts: 40
Joined: 04 Aug 2021, 23:25
Location: DE

Re: Random choise mp3 playlist

#37 Post by Sminter4 » 29 Apr 2025, 21:45

With the few tests I was able to perform, I couldn't find any errors in the random function. 👍

For my application, I don't need any decimal places. However, I can round them with

Code: Select all

 [int#1]
However, this only seems to work with the number variables. The name variables are spitting out incorrect values ​​here.

Code: Select all

[int#%v_random%]
It seems as if the next largest number variable is simply rounded instead of the word variable.

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#38 Post by TD-er » 29 Apr 2025, 22:12

Code: Select all

let,1,%c_random%(1,100)
logentry,"My random value: [int#1]"
Have you tried it like this?

Or

Code: Select all

let,1,%c_random%(%v_min%,%v_max%)
let,random,[int#1]
logentry,"My random value:  %v_random%"
Not sure if floating point values as index will be parsed very well.
Never tested it.

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#39 Post by Ath » 29 Apr 2025, 22:18

Sminter4 wrote: 29 Apr 2025, 21:45 With the few tests I was able to perform, I couldn't find any errors in the random function. 👍

For my application, I don't need any decimal places. However, I can round them with

Code: Select all

 [int#1]
However, this only seems to work with the number variables. The name variables are spitting out incorrect values ​​here.

Code: Select all

[int#%v_random%]
It seems as if the next largest number variable is simply rounded instead of the word variable.
That should be:

Code: Select all

let,random,%c_random%(1,100)
...[int#random]...
to get the integer value of your random number
/Ton (PayPal.me)

Sminter4
Normal user
Posts: 40
Joined: 04 Aug 2021, 23:25
Location: DE

Re: Random choise mp3 playlist

#40 Post by Sminter4 » 29 Apr 2025, 22:50

I tested the commands on the tools page. And I can now confirm that this syntax works:

Code: Select all

[int#random]
If it's well documented, it shouldn't be a problem...

TD-er
Core team member
Posts: 9879
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Random choise mp3 playlist

#41 Post by TD-er » 29 Apr 2025, 22:57

Well Ton made the named variables, so without having read the docs, I can be sure he did a good job.

And Ton can confirm I didn't read the docs for it, judging our Signal chat of a few minutes ago :)

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Random choise mp3 playlist

#42 Post by Ath » 30 Apr 2025, 22:02

For reference, the use of Internal variables is documented here
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests