In my application, I will be creating multiple Audio Tracks, some of which will need to play simultaneously. I’m going to use MODE_STREAM and write data in as the app runs. Sounds are going to be dynamically generated, which is why I use Audio Track as opposed to anything else.
I have 4 options, I believe:
- AsyncTask
- One UI thread and one thread that manages all the AudioTrack playing
- One UI thread and one thread for each AudioTrack
- One UI thread and a Thread Pool
Which of the four methods would be the best way to manage multiple AudioTracks?
I think Thread Pool is the way to go, but I’m not positive as I haven’t actually used it.
Any advice would be greatly appreciated
For simplicity, I was just creating a new thread every time I played an AudioTrack.
But, regardless it really doesn’t matter. I found that when trying to play more than one AudioTrack at a time, there’s a crackling/choppy sound. I believe this is just an issue with the Android system, not with my app.
As of API level 9 (gingerbread) I can apply a session id to an audio track, which I believe would let me play it with SoundPool, which should make the playing of multiple AudioTracks at once much smoother.
Right now, due to how many users are still on 2.2 and the fact that I don’t have a gingerbread device, I will put this project aside until later.