# \[Solved\] How do I play music in a shuffled order?

**URL:** <https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152>\
**Category:** Questions about Thunkable X\
**Tags:** solved, spreadsheets, audio, media, airtable\
**Created:** [October 17, 2019, 12:08pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152 "2019-10-17T12:08:36Z")\
**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:** [October 17, 2019, 12:08pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/1 "2019-10-17T12:08:36Z")

</div>

Hi Everyone! 👋

So this is what I need it to do:

I need to have a column in the Airtable with the urls to MP3s.

I need the user to click a category (EG: “stressed”) and this will start playing the Airtable “stressed” with MP3s listed.

I want the audio MP3s to play one after another, automatically (unless the user clicks “pause” or closes the screen) and these should play in a random, shuffled order, not one after another. That is also important. 🙂

Does this make sense?

Thanks! 😊

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [October 17, 2019, 4:11pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/2 "2019-10-17T16:11:18Z")

</div>

This might require a little bit of extra effort on your part @looovelee as the Sound component currently doesn’t have any `Sound.stoppedPlaying` event.

Do you know the track duration for each of your tracks? I would recommend adding this value, in seconds, to an additional column in your spreadsheet and this way you can use the Timer component to start change the source and start playing as soon as the song is finished.

Hope that helps.

---

<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:** [October 19, 2019, 12:19pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/3 "2019-10-19T12:19:41Z")

</div>

Hi Domhall,

Thank you for the heads up! I suppose putting the length of the audio file in each row wouldn’t been too taxing. I have got as far as making an Airtable excel with sample audio files and linked the API, etc to the app.

Would anyone be able to show me a sample of the blocks to pull in this column of audio files to play? Even if it can only successfully do one. I’ve been stuck here for weeks and have no idea how to connect the link address in Airtable to my app to play any of them. The added layer of the timer component on that is really making my head spin, but maybe if I have someplace to start from I can figure that out as well…

Any guidance would be SO appreciated. I have no idea how to do this. First app. No dev experience. Trying trying trying to learn. 😅😅😅😅

Thank you!

Unsure how to proceed. These are the blocks:

 ![06](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/9/9990d25d065d25e7cb89aed49871a2788bcb59b3.png)

Airtable:

 ![10](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/9/99abf6d7ca997a6c1e808454772fde49e0cdc1f5.png)

---

<div class="post-metadata">

**Author:** ![jane](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jane/32/27575_2.png) [@jane](https://community.thunkable.com/u/jane)\
**Post date:** [October 19, 2019, 11:16pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/5 "2019-10-19T23:16:43Z")

</div>

Hi @looovelee,

I have 2 recommendations:

1. Putting blocks after navigating to a new screen is not what we’d call best practise. Instead, say ‘when btn\_good Click, navigate to Media’, then have certain functions trigger when the Media screen opens. Which is my next recommendation:

2. These blocks should keep playing random tracks from your list of music indefinitely!

We use the **recursive** function ‘set track’. A recursive function is one that calls itself. ‘set track’ will pick a random track, then play it, then call ‘set track’ which will pick a random track, then play it, then call ‘set track’, which will… to infinity! (Or until the user presses STOP.)

When ‘set track’ randomly selects a track, it will _probably_ not be the same as the track that was just played. In that case, we set the new Sound source, use the ‘on Source loaded’ block to play the sound, and call ‘set track’ again to keep to cycle going.

However, if the track we just selected is the same as the existing track, the ‘on source loaded’ block won’t be called! Instead, we’ll use the ‘in Sound call Play’ block to play the track again, then call ‘set track’.

![random%20music](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/0/0035dfaea6f46356d8ce4b7314926ec796d0e686.png)

Note: I used the LocalDb component in this screenshot, you can of course get an Airtable column when the screen opens as well. 🙂

Let me know if this works for you,

Thanks!

---

<div class="post-metadata">

**Author:** ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)\
**Post date:** [October 20, 2019, 12:32pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/6 "2019-10-20T12:32:12Z")

</div>

### This is the Perfect Solution ✅ 👏

---

<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:** [October 22, 2019, 11:47am UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/7 "2019-10-22T11:47:21Z")

</div>

Hello Jane,

Wow! Thank you so much. Thank you for the explanation and the block screenshot. This makes a lot of sense as I read it. 😁 👏

I have a question now if are able to assist? 😅

On the screen _before_ media are 4 categories for the user to choose: good, stressed, etc. I wanted the user to navigate to Media page and only play mp3s from one category.

There is also another, separate audio file playing (background guitar) _in addition_ to the audio tracks pulled from the table. 😅

**The goal:** The user clicks a category on Screen 1 which navigates them to the Media page and then as they arrive there, the 1st background guitar starts playing on a loop. These random tracks that we are calling from the local DB table (good, mad, sad or stressed) will also begin to play (on shuffle / random) _at the same time_.

 ![Screenshot_20191022-133036_Thunkable](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/0/d03146d9b3e9a8af74277118966031173334d8a9.jpeg) ![Screenshot_20191022-133139_Thunkable%20(1)](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/7/87c3693b0780acd5629feedb6d671f3eb26f6fed.jpeg)

If the user clicks “pause”, everything pauses. They click play again everything resumes. They can leave the screen at any point and everything stops / resets. They can choose a different category next time.

Here is what I have after adding your recommended blocks. When I live test it, the background guitar is playing when I click play and none of the sample audio files from the local table are playing. I guess the blocks are contradicting each other somewhere?

 ![mediapagenew](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/a/5a9dcdac177061a673fb2f7a2452ec757c54ea67.png)

Thank you again! I can’t tell you how much I appreciate the help already!

---

<div class="post-metadata">

**Author:** ![jane](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jane/32/27575_2.png) [@jane](https://community.thunkable.com/u/jane)\
**Post date:** [October 23, 2019, 5:12pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/8 "2019-10-23T17:12:11Z")

</div>

Hi @looovelee,

I think the problem is with your ‘set track’ blocks.

You’ve added an extra ‘list’ block into the ‘in list [app tracks] get #’ block.

You can see that this isn’t the case with my blocks!

Try taking this extra ‘list’ block out and test your app again.

Thanks,  
Jane

---

<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:** [October 24, 2019, 12:54pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/9 "2019-10-24T12:54:15Z")

</div>

Hello Jane,

Thank you very much. I gave that a try, but the audio tracks are still not playing for me. Only the background Guitar music.

I’ve highlighted these 2 areas below, do you think they are cancelling each other out?

Should I combine the two “when Media opens” blocks? Is that good practice?

 ![38](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/1/71da5305800ba060efccad4ea0c0cc99ea4f7328.png)

Many thanks again!

---

<div class="post-metadata">

**Author:** ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)\
**Post date:** [October 24, 2019, 1:38pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/10 "2019-10-24T13:38:34Z")

</div>

> [@looovelee](#):
>
> I’ve highlighted these 2 areas below, do you think they are cancelling each other out?

Nope. The platform is confusing which one to do first…

> [@looovelee](#):
>
> Should I combine the two “when Media opens” blocks? Is that good practice?

Yep.  
Move the **`backgroundGuitar - play`** block (from the second screen-opens block) below the **set track** function (in the 1st screen-opens block).

Thanks 😊

---

<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:** [October 24, 2019, 1:56pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/11 "2019-10-24T13:56:04Z")

</div>

Hey! Thank you for the tips. 😅

So, when I did this, no audio would play until I clicked the “pause” button.  
So when I put background guitar above these blocks, it will play, but not the tracks.

**My goal:** Is to have both the background guitar and the tracks playing _at the same time_. Right now I am not hearing any of the tracks from the track list at all? Is there some way to achieve this?

---

<div class="post-metadata">

**Author:** ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)\
**Post date:** [October 24, 2019, 1:57pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/12 "2019-10-24T13:57:40Z")

</div>

> [@looovelee](#):
>
> So when I put background guitar above these blocks, it will play, but not the tracks.

Did you put the **`tracks`** procedure under the **then-do** section?

---

<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:** [October 24, 2019, 2:00pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/13 "2019-10-24T14:00:06Z")

</div>

Yes. I think so? 😅

 ![29](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/5/85f424de67c6874b99347ed25b39ff7afdd5af45.png)

---

<div class="post-metadata">

**Author:** ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)\
**Post date:** [October 24, 2019, 2:02pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/14 "2019-10-24T14:02:55Z")

</div>

Try adding the **`tracks variable`** above the play block.

---

<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:** [October 25, 2019, 12:50pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/15 "2019-10-25T12:50:54Z")

</div>

Hey Kartik.

I tried this and have also removed all mention of the background guitar. No tracks are playing.

Is there something else missing here?

 ![14](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/6/6649d8b31678ceb930d9a958e90d18df5f4b86b4.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:** [October 25, 2019, 1:08pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/16 "2019-10-25T13:08:00Z")

</div>

Maybe this is it… 😅

Does the sound component support .m4a files?

Well, even so, I checked it with this sample audio and it does not work:  
[https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3](https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3)

 ![07](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/4/04ae563a84f02444823d0d656b630c18fe8fb82f.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:** [October 25, 2019, 1:13pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/17 "2019-10-25T13:13:06Z")

</div>

Hey Jane,

If you have more time, would you please see the most recent feedback I sent to Kartik. This is not working yet. I removed the second background audio to simplify it. I just want to ensure that the tracks will come in and play with the pause button activated. I can put the background audio back in after this is set up. 🙂

Do you see anything else that I’ve set up wrong? 😪

Many thanks!

---

<div class="post-metadata">

**Author:** ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)\
**Post date:** [October 25, 2019, 1:26pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/18 "2019-10-25T13:26:51Z")

</div>

Hi,

> [@looovelee](#):
>
> ![14](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/6/6649d8b31678ceb930d9a958e90d18df5f4b86b4.png)
> 
> Screen Shot 2019-10-25 at 13.43.14.png1340×1326 170 KB

In this one, you have the block **`screen1 starts`** instead of **`screen1 opens`** block.

This can be it, please test 😇

Also, I am examining your code.

---

<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:** [October 25, 2019, 1:29pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/19 "2019-10-25T13:29:40Z")

</div>

Ah yes!

I was trying a few things before. 🙃

I have it back to **Media opens** block. Nothing yet!

---

<div class="post-metadata">

**Author:** ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)\
**Post date:** [October 25, 2019, 1:29pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/20 "2019-10-25T13:29:55Z")

</div>

> [@looovelee](#):
>
> Does the sound component support .m4a files?

Using **`.mp3`** would be good instead of **`.m4a`**. Also, I have tested **.`mp3`** files - they work.

Thanks! 😊

---

<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:** [October 25, 2019, 1:31pm UTC](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152/21 "2019-10-25T13:31:36Z")

</div>

Thanks! Mp3s not working for me either right now. 😅

[Next page](https://community.thunkable.com/t/solved-how-do-i-play-music-in-a-shuffled-order/276152.md?page=2)
