开发者

How to make music plays from beginning of the app until a viewcontroller has been presented?

开发者 https://www.devze.com 2022-12-30 00:42 出处:网络
Hey guys I have a problem with an app I\'m making. The thing is I want to add it some background music, but I just want to add it in the main view.

Hey guys I have a problem with an app I'm making. The thing is I want to add it some background music, but I just want to add it in the main view.

My app has 3 view controllers: Main View Controller, Second View Controller and Third View Controller.

What I want is to start the music in the Main View Controller and stop it when the T开发者_StackOverflow中文版hird View Controller is presented.

I think I have to start the music in my app delegate and from there stop it, am I right?


Yes. Simplest way is to create a player (I have my own soundplayer class that sets up the audiosession etc) and start the music in the appDelegate (or 1st VC as appropriate). You then have a structural choice - pass the player through all of your VC's (which is the right way) and then the 3rd VC can stop it playing, or cheat, and allow the 3rd VC to do [appDelegate.player stop].

0

精彩评论

暂无评论...
验证码 换一张
取 消