Is there any way you can combine the two functions, or at least, combine their main logic? At the end of it, the only real differences is in how it gets the audioTracks, and even then, it's pretty similar. I would maybe move the looping/setting to a separate shared function?