# Smart Audio Shuffle

**URL:** <https://community.thunkable.com/t/smart-audio-shuffle/771047>\
**Category:** Questions about Thunkable X\
**Tags:** beginner\
**Created:** [August 26, 2020, 2:07pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047 "2020-08-26T14:07:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [August 26, 2020, 2:07pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/1 "2020-08-26T14:07:48Z")

</div>

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? 😅

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

 ![Screen Shot 2020-08-26 at 15.04.38](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/8/d8314b7bb82fa3b5c4877b700ac65740a3245e27.png)

Thank you all for your time and advice! 🙂

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [August 26, 2020, 2:53pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/2 "2020-08-26T14:53:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [August 26, 2020, 3:25pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/3 "2020-08-26T15:25:56Z")

</div>

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

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

> [@tatiang](#):
>
> The second time through steps 2-4, you’ll get a randomTrackNum value but the list item value may not match it.

What do you mean? Can you clarify? 🤔

Thanks a million!

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [August 26, 2020, 4:36pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/4 "2020-08-26T16:36:56Z")

</div>

Here’s a demo:

[https://x.thunkable.com/copy/6c8871f4a3361eb051852a34149ec8cd](https://x.thunkable.com/copy/6c8871f4a3361eb051852a34149ec8cd)

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 9, 2020, 1:31pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/5 "2020-09-09T13:31:18Z")

</div>

Good afternoon Tatiang! 👋🏼

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. 🙂

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?

 ![Screen Shot 2020-09-09 at 14.22.05](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/2/c21eff128bb2c00c6a549df8c96f66a6f5d1a4f3.png)

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. 😆

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 13, 2020, 6:11pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/6 "2020-09-13T18:11:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 14, 2020, 4:44am UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/7 "2020-09-14T04:44:25Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 14, 2020, 8:14am UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/8 "2020-09-14T08:14:40Z")

</div>

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

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? 🤔 I’ve tried to replicate the demo as closely as I could with my existing blocks.

Appreciate your time and help!

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 21, 2020, 2:56pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/11 "2020-09-21T14:56:04Z")

</div>

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.

 ![Screen Shot 2020-09-21 at 15.50.40](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/a/5aef47ceee53668566fb8d971bcfff7104cacea7.png)

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. 🤔

There must be a simple way that I am missing… any help would really be appreciated! 😅 😌 🙏🏼

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

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 22, 2020, 8:38am UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/12 "2020-09-22T08:38:27Z")

</div>

Hello! 👋🏼 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).**

> [@Smart Audio Shuffle](http://community.thunkable.com/t/smart-audio-shuffle/771047/5):
>
> 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?

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 22, 2020, 2:12pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/13 "2020-09-22T14:12:20Z")

</div>

> 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)**

😩

 ![Screen Shot 2020-09-22 at 15.09.10](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/f/7fc0d535333f1528bb961a554ecfdf3e2ee3f893.png)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 22, 2020, 2:51pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/14 "2020-09-22T14:51:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![secondaryaccount](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/secondaryaccount/32/91441_2.png) [@secondaryaccount](https://community.thunkable.com/u/secondaryaccount)\
**Post date:** [September 22, 2020, 10:00pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/15 "2020-09-22T22:00:34Z")

</div>

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:

 ![Screen Shot 2020-09-22 at 3.00.13 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/0/e0397a99dbe3f04d16b72fc2d391d1bc84d96d0f.png)

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 24, 2020, 1:05pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/16 "2020-09-24T13:05:54Z")

</div>

Good afternoon! Thank you for your reply. 😃

(Updated blocks below)

 ![Screen Shot 2020-09-24 at 13.59.00](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/5/25eba3d161c728c984011d13ccbdbbbba6ad2a44.png)

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! 👏🏻

**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. 🤔

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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 24, 2020, 4:09pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/17 "2020-09-24T16:09:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 24, 2020, 6:05pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/18 "2020-09-24T18:05:24Z")

</div>

Thank you for your advice Tatiang! 😃

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

Am I missing a step? 🤔

 ![Screen Shot 2020-09-24 at 19.03.34](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/6/563ed139a7d619fe97ed0532e7fb4de0203f3e8b.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 24, 2020, 6:42pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/19 "2020-09-24T18:42:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 25, 2020, 12:48pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/20 "2020-09-25T12:48:17Z")

</div>

Thank you so much Tatiang! 😄

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!!! 👏🏻 👏🏻 👏🏻

Thanks again!

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 25, 2020, 1:27pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/21 "2020-09-25T13:27:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![looovelee](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@looovelee](https://community.thunkable.com/u/looovelee)\
**Post date:** [September 25, 2020, 2:29pm UTC](https://community.thunkable.com/t/smart-audio-shuffle/771047/22 "2020-09-25T14:29:47Z")

</div>

The mental pain is 💯% worth the gain! 🙃 🤣 👏🏻

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

[Next page](https://community.thunkable.com/t/smart-audio-shuffle/771047.md?page=2)
