Thank you for sharing the solution.
By the way, have you tried to make a script to play the list of mp3 files in local media folder in ordering by file name?
For example there are 3 mp3 files in /media folder as below:
1.mp3
2.mp3
3.mp3
The expectation is when start the script, the file 1 will be played first then file 2, then file 3 etc.
Same issue here, did you manage to resolve the “local” issue?
edit: I found a workaround, in your example… just add a folder “local” to “media” and copy “quran” to “local” … this breaks the manual selection of a media file but the randomise works…
Hi. Would you mind showing me how I can edit this working code to play in order from folder? I am stuck on how to add the repeat.index... part. The random is repeating over and over.
play_random_track:
alias: Play Random Music Track
sequence:
- service: media_player.play_media
data:
media_content_id: "{{ state_attr('sensor.music', 'file_list')|random |replace('media/','media/local/') }}"
media_content_type: audio/mp4
target:
entity_id: media_player.razer_leviathan_player
Your version is working and the music starts selectively, but for some reason one track of music is played when there are several dozen tracks in the folder. How do I make all tracks play?
If I run like this, then the track playback starts selectively, but plays one track
To solve my problem, I resorted to automation and implemented it as follows, It works. I added an auxiliary switch “Music Playback” and it turns on simultaneously when starting music once, then as soon as the MPD player stops working and changes the status from playing to off, a trigger is triggered and runs a script that starts a selective track and it will be non-stop until we turn off the auxiliary switch “Music Playback” and the MPD player itself
alias: "ReSpeaker: Play music non-stop"
description: >-
When we start to play music selectively, only one plays
the track is selective and will not be played anymore. To play the next track, you need to
re-run the script to run the sample music. This automation will be
run the script every time the music finishes playing, provided that
the "ReSpeaker: MPD" switch is on. Play music selectively"
trigger:
- platform: state
entity_id:
- media_player.mpd_respeaker
to: "off"
alias: MPD ReSpeaker turned off
condition:
- condition: template
value_template: "{{ is_state('input_boolean.respeaker_mpd_music_playback','on') }}"
alias: Music playback is enabled
action:
- service: script.respeaker_mpd_play_music_selectively
data: {}
mode: single
The script itself for launching random music
service: media_player.play_media
data:
enqueue: play
media_content_type: music
media_content_id: >-
media-source://media_source{{ state_attr('sensor.music',
'file_list')|random}}
target:
entity_id: media_player.mpd_respeaker
Failed to cast media media-source://media_source//media/example.mp3. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
Not sure what the update changed. Just trying to cast a single file without the random selection script added in still works fine.
Sorry for reviving an old thread, didn’t want to start a new one for a small question
With the “random” play of audio clips. Is there a way I can set it to play random but not play anything that’s already been played until every clip has been played once, and then restart the process again?
I find the “randomness” not so random even though there are 65 files
I understand this could be very complicated, but very interested to see if there’s a way