本文介绍了iOS如何在启动应用程序时不停止音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到当我的应用程序启动时,我正在听的音乐会自动停止,并且我注意到当我启动其他一些应用程序时,音乐只会继续...这意味着我没有知道如何管理设备中的实际播放音乐以使其播放或停止.

I've noticed that when my app start, the music I'm listening is automatically stopped, and I've noticed that when I start some other apps, the music just continue... this means that I don't know how to manage the actual playing music in the device to let it plays or stop.

我正在用obj-c和cocos2d btw开发一款游戏,我进行了搜索,但可惜我什么都没找到...所以这是我的问题,如何让我在设备上收听的音乐继续播放即使启动应用也可以玩吗?

I'm developing a game with obj-c and cocos2d btw, I've searched but sadly I've found nothing... so here's my question, how can I let the music I'm listening with my device continue to play even if I start the app ?

我正在使用SimpleAudioEngine在我的应用程序中启动背景音乐和一些声音效果

edit: I'm using SimpleAudioEngine to start a background music and some sound effects in my app

推荐答案

将此行放在您的应用程序:didFinishLaunchingWithOptions:您的AppDelegate的方法中,或者通常在使用音频播放器之前.

Place this line in your application:didFinishLaunchingWithOptions: method of your AppDelegate or in general before using the audio player.

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];

根据文档,AVAudioSessionCategoryAmbient类别为

According to the documentation, the AVAudioSessionCategoryAmbient category is

请导入AVFoundation/AVFoundation.h

这篇关于iOS如何在启动应用程序时不停止音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:29