[Guide for absolute Newbies] How to achieve a switch button for music (enabled/disabled)

Hello Koders,

Today, I wanted to show how to make a switching button for turning a music ON or OFF. I had to use this in my own app now nearly finished, so I thought to make a Tutorial here.

This (first) tutorial is very simple and not the best at all :sweat_smile:, but it’s an interesting thing and nobody came up with the idea.

So, let’s start:

Designer:

We will use three components:

  1. A button
  2. A player (in my case, ExoPlayer)
  3. TinyDB

image

Now I have three assets that are not really neccessary for the logic, but for the result:

  1. A music
  2. A “unmute” image
  3. A “mute” image

That’s all in the Designer, let’s get into the kode!

We will have two block sections to get this working:

So, that’s it, guys!

If you have any questions or I did anything wrong to this guide or want to improve it, feel free to comment here. I am open to suggestions :innocent:

All your friend, @Yoshi :stuck_out_tongue_winking_eye:

PS : If anyone wants the .AIA file, here is it:
MusicSwitchGuide (1).aia (1.6 MB)

EDIT 1: Updated kode of TinyDB in Button on suggestion from @Kanishka_Developer. Thx!

IMPORTANT: EDIT 2: This is only for a sound switch between screens, for one screen use variables and not TDB.

13 Likes

Good first guide. :+1: You explain every block you used.

Nice music Buddy | Happy Royalty Free Music - Kids

2 Likes

That AIA is huge! :scream:
Btw, nice first guide.

1 Like

Just for someone who want to see everything So really nobody I think :smile:

Great guide, @Yoshi. Just one suggestion: in the TinyDB get block, use false as the valueIfTagNotThere fallback value. :slight_smile:

1 Like

:grimacing:
Yeah I usualy use this value wisely, but this time, the code works bc it’s so easy. That’s why I just ignored it :stuck_out_tongue_winking_eye:

EDITED. Also the .AIA file FYI, guys.

1 Like