Jump to content

Need guidance on making seek slider control audio.

daweakling

So I am working on a project in Android Studio (Java) making an app with a simple slider bar that would play different sound files at various variables of the slider bar. For example if the slider bar = 0 , then it would play audio 0; if the slider bar = 1, then it would play audio 1. I was tinkering around and I don't know of an efficient way of implementing this. 

 

I made a slider bar with an "on change" method. Inside the "on change" method I made a big loop, which had a BUNCH of if statements. Those if statement would read the slider bar value and run the statement if they matched. Each if statement had separate code to run the appropriate audio file. 

 

Some programmers are probably face palming so hard when reading this but I am a noob with programming. There has to be an easier and more efficient way. I am gladly open to all opinions and comments. 

Specs: Intel Core i7 2600k | Gigabyte Z68-UD3H-B3 | EVGA 1080 FTW2 Gaming | Kingston HyperX Red 16GB | Cooler Master Hyper 212 Evo | Corsair CX600 | 
Lian Li Lancool-II white

 

Laptop: ASUS ROG Zephyrus M15 (Intel i7, 16GB, RTX 2070) | 2013 MacBook Pro 15 (Intel i7, 16GB, GT750M)

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

As far as it is not android specific question then I think that array of strings with file names and the slider value would be an index of the array, just make sure to check if the value is not out of array's bounds. Then you get a file name from the array by index (value of slider) and play it, so no ifs.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×