因此,我有一段音乐在 AppDelegate 中开始播放(基本上当应用程序加载时),并且我希望在按下具有自己的 ViewController 类的设置场景上的按钮后使其停止。 如何才能实现这一目标?如何访问启动音乐的 appDelegate 类中的变量? 以下是在 AppDelegate 中启动音乐的代码:
var themeAudioURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("theme", ofType: "mp3")!)
var themePlayer = AVAudioPlayer()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
themePlayer = AVAudioPlayer(contentsOfURL: themeAudioURL, error: nil)
themePlayer.volume = 0.05
themePlayer.numberOfLoops = -1
themePlayer.play()
return true
}
最佳答案
您可以将玩家传递到下一个场景。您可以在准备 segue 方法时执行此操作。或者,您可以在另一个 View Controller 中获取应用程序委托(delegate)并将其转换为您的应用程序委托(delegate)实现。
关于ios - 使用 Xcode 中另一个场景中的按钮暂停音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31039414/