Smart Audio Shuffle

I’ve been working on a media app that calls in and plays 100+ audio files, in a shuffled order. It’s already working great (thanks to much help from fellow Thunkers!), but I don’t want audio files to repeat as often as they do.

My goal is ensure that all of these audio files are played only 1x before any of them are played a second time. As with the first play, they should not repeat a third time until the entire set of audio files have played a second time.

Does that make sense? :sweat_smile:

Here are the blocks I have for the shuffle. (Note: There is also looping background music, that is separate to the shuffled audio files.)

Thank you all for your time and advice! :slight_smile:

  1. Create a list with values from 1 to the number of tracks you have.
  2. Pick a random number from 1 to the length of the list (let’s say you pick 14) and assign it to a variable which we’ll call randomTrackNum.
  3. Play the track that matches the value (in this case, 14) of the list item at index randomTrackNum.
  4. Delete the list item at the index randomTrackNum (14).
  5. Repeat steps 2-4 until your list is empty.
  6. Re-populate the list and repeat steps 1-6 if desired.

The second time through steps 2-4, you’ll get a randomTrackNum value but the list item value may not match it.

1 Like

Thank you so much! I appreciate your help.
Unfortunately, the list side of things truly confounds me… if I don’t see sample blocks. :sweat_smile:

Will steps 1-6 need to replace most of the blocks here? Or can I build it upon these blocks?

What do you mean? Can you clarify? :thinking:

Thanks a million!

Here’s a demo:

1 Like

Good afternoon Tatiang! :wave:t3:

I apologise for the late reply! Thank you so much for the demo!
That was incredibly helpful for me and I understand a lot better now with the visualization. :slight_smile:

I tried my best to adapt this into the blocks I had. It didn’t break anything (thankfully!), but it also hasn’t accomplished it. My test brought back a few repeated tracks only a few tracks in. Is there any obvious oversight here that stands out to you?

Also, at the end of the completed list in your demo, the finale is the text : “All tracks have been played” - is there an easy way to set this process to reset my list and keep playing on a loop - so that this process happens an infinite amount of times? Always repopulating when all the played tracks are done?

Thank you again for all of your help!! This is quite a journey. :laughing:

If anyone has any advice, I’d really appreciate it! Very stuck. :anguished:

I think you’d just make a copy of your track list, then use the copy for playing random tracks. Once there are no tracks left, you just repeat: copy the track list, use the copy for playing random tracks… repeat…

1 Like

Thanks Tatiang! Ok… I will look at setting it up to replicate the list x infinity. :blush:

Before that though, I am still having trouble. I have 20 tracks that come into the list to stream and I am getting repeated audio before going though the list.

Do you notice where I’m going wrong? :thinking: I’ve tried to replicate the demo as closely as I could with my existing blocks.

Appreciate your time and help!

Hey Tatiang,

I’ve adjusted the blocks significantly… now it’s working 1x on shuffle, removing the played tracks as they go. This works great.

Could you please help me understand the best way to make a copy of the track list and use the copy for playing tracks (x infinity)?

I am unsure how to do this effectively without copious amounts of code… and even then it wouldn’t be set to continue forever, just as much as I’ve replicated these lists and apps. :thinking:

There must be a simple way that I am missing… any help would really be appreciated! :sweat_smile: :relaxed: :pray:t3:

Many thanks everyone! I really appreciate your expertise so much!

Hello! :wave:t3: I think this is what I need to do as well!

Would someone please show me the blocks that illustrates what you’ve said to do here:

“Have a variable to store the original list and whenever you want to restore it just assign this variable to the listview.items property.”

My app pulls in tracks to play into a list, then deletes them as they’re played. It stops playing when they’re all gone, but my goal is to have the list to refresh once it’s empty and replay (x infinity).

I think you’d just make a copy of your track list, then use the copy for playing random tracks. Once there are no tracks left, you just repeat: copy the track list, use the copy for playing random tracks… repeat…

There must be a simple way to do this… this isn’t working… any advice? Anyone out there? (hears echo)


1 Like

I can see from your [If Block] that you are either setting the track or playing the track but not both which will result in playing few tracks only depending on the result of the random number generated.

Can you please verify it?

1 Like

This is @tatiang… not sure why I can’t log out and log back in as myself but… okay.

Sorry, I’m really busy with work and not on the forums as much as I’d like to be.

I don’t use local databases in Thunkable so I’m not as familiar but if you had used a list for the your track info, then you would do something like this:

1 Like

Good afternoon! Thank you for your reply. :smiley:

(Updated blocks below)

This is what the app is doing: When Media screen opens, it pulls in 20 tracks from Database and plays each one, in a random order. As it plays each track, it removes this track from the list. That way, they will not play more than one time. This is great! :clap:t2:

My Goal: After the list is all played & emptied, have the list pulled in again from the database and play each one, exactly as before. Ideally, I would like this process to continue an infinite amount of times. Keep pulling, playing, removing, restart.

I can’t figure out how to get the tracks to reload and replay after the 1st time. :thinking:

Thank you so much for your time and any advice would be SO appreciated!

I think you already have what you need. The blocks in the when Media Opens event reset the track list. So just use that same set app tracks block when you need to start over.

1 Like

Thank you for your advice Tatiang! :smiley:

I added these blocks at the end, but nothing happens when the list finishes emptying the first time.

Am I missing a step? :thinking:

1 Like

That looks good to me but I don’t see anything calling the function “restart.” A function can’t just run on it’s own. So the if app tracks is empty block won’t actually check anything unless you have the restart function call block somewhere. But if you already have that and I just don’t see it in the screenshot AND it’s not working, it’s time to debug your code. Add some In label ____ set text to ____ blocks throughout your code (I’d start inside the restart block) and number then “1”, “2”, “3”, etc. Then watch your code to see how far it gets.


Thank you so much Tatiang! :smile:

This is working perfectly now. I was missing the restart function call block.

As a beginner, I miss some of these more obvious steps. I am learning so much! I’m really enjoying the education, even though it’s frustrating at times. I appreciate all of your advice on this - it’s so exciting to see it working properly now. Awesome stuff!!! :clap:t2: :clap:t2: :clap:t2:

Thanks again!


Glad to hear it’s working! Yes, coding is always a bit frustrating for me but also quite rewarding. And I’m still learning Thunkable myself but trying to also share what I know. It helps that I have somewhat of a programming background from college.


The mental pain is :100:% worth the gain! :upside_down_face: :rofl: :clap:t2:

I’m a huge fan of Thunkable and this community is awesome. Thanks again!