<!--- Get full path to mp3s. ---> <cfset ...
# cfml-beginners
<!--- Get full path to mp3s. ---> <cfset mp3Directory = expandPath(".")> <!--- Get directory ---> <cfdirectory action="list" directory="#mp3Directory#" name="mp3s" filter="*.mp3"> <!--- Do we have any mp3s? ---> <cfif mp3s.recordCount gt 0> <!--- How many mp3s? ---> <cfset totalMp3s = mp3s.recordCount> <!--- Pick one ---> <cfset pickedIndex = randRange(1, totalMP3s)> <!--- get the file ---> <cfset mp3 = mp3s.name[pickedIndex]> <!--- play it ---> <!---<cfoutput><img src="#image#"></cfoutput>---> <cfoutput><cfmediaplayer name="DJ" autoplay="true" source="#mp3#" controlbar="true" quality="high"></cfoutput> </cfif>
you can set up a javascript function that refreshes the screen and add the function name to the onComplete argument on the cfmediaplayer tag
something like this (untested):
Copy code
<script type="text/javascript">
    function playNext(){

<cfmediaplayer name="DJ" autoplay="true" source="#mp3#" controlbar="true" quality="high" onComplete="playNext">
Side note: if you want to avoid repeats, you will probably want to modify this script to keep track of what was already played in this session, then randomly pick from the songs that have not been played yet.
👍 1
🙌 1
Thanks a lot. I was thinking that was the right route.
👍 1
your untested js has been tested and works great. I'd show you, but I'm having trouble forwarding the ports of my lucee seerveer :(