音乐与声音一起播放,但在首次发布时暂停音乐。如何在启动时让背景音乐继续播放?

时间:2016-09-19 16:26:54

标签: ios swift audio sprite-kit

我关注了这篇文章:SKAction playSoundFileNamed stops background music它的工作原理是当SK声音动作运行时,音乐不再暂停。

不幸的是,当应用程序最初启动时,音乐仍然停止。我也尝试过其他帖子(background device music gets stopped as app starts ios)的代码,但要么不起作用。

如何阻止我的应用在初次发布时暂停音乐?也许我没有将我的代码放在正确的位置?

代码:


    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        do {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
        } catch _ {
        }
        do {
            try AVAudioSession.sharedInstance().setActive(true)
        } catch _ {
        }
    }

谢谢!

编辑1(用于评论)

{{1}}

0 个答案:

没有答案