Make AVAudioPlayer stop playing in a different View Controller?
Hi. I recently created an app that has background music playing (and looping) through an AVAudioPlayer. I start it when the 1st view controller is finished loading. What happens is the user clicks a button on the 1st view controller (loading screen) then it switches to the second view controller (main menu) and the music keeps looping uninterrupted. The user then clicks on a start game button and it switches to the 3rd view controller (the game). I want it to stop on the 3rd view controller (which again is the actual game). Here's the code I used:
The function changeLoadingTextToTapToStart is set up on a timer and set to activate when the view finishes loading. How would I stop the looping and sound altogether in the 3rd view controller?
Hi. I recently created an app that has background music playing (and looping) through an AVAudioPlayer. I start it when the 1st view controller is finished loading. What happens is the user clicks a button on the 1st view controller (loading screen) then it switches to the second view controller (main menu) and the music keeps looping uninterrupted. The user then clicks on a start game button and it switches to the 3rd view controller (the game). I want it to stop on the 3rd view controller (which again is the actual game). Here's the code I used:
The function changeLoadingTextToTapToStart is set up on a timer and set to activate when the view finishes loading. How would I stop the looping and sound altogether in the 3rd view controller?
There's way too many possible answers for anyone to give you. You could pass an object pointer from one view controller to another, put the AVAudioPlayer in your app delegate, or inside of a singleton class. I've seen posts in the forum arguing for each of the above, with no decision on which is best.
I would recommend you search this forum, and Google a bit, and pick one of these approaches. Then if you have trouble making it work, post back here with questions.
There's way too many possible answers for anyone to give you. You could pass an object pointer from one view controller to another, put the AVAudioPlayer in your app delegate, or inside of a singleton class. I've seen posts in the forum arguing for each of the above, with no decision on which is best.
I would recommend you search this forum, and Google a bit, and pick one of these approaches. Then if you have trouble making it work, post back here with questions.
Thanks for the great foundation to work off of. I will definitely post back here if I have any further questions.