iOS如何在启动应用程序时不停止音乐 [英] iOS how to don't stop music when the app start launching

查看:1607
本文介绍了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

对于非主要声音播放的应用程序-也就是说,您的应用程序可以 在声音关闭的情况下可以成功使用. 此类别也适用于伴奏"风格的应用程序,例如用户通过iPod音频播放的虚拟钢琴.当你 使用此类别,其他应用程序的音频会与您的音频混合在一起.你的 屏幕锁定和静音开关可将音频静音(称为 iPhone上的铃声/静音"开关.

for an app in which sound playback is nonprimary—that is, your app can be used successfully with the sound turned off. This category is also appropriate for "play along" style apps, such as a virtual piano that a user plays over iPod audio. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).

请导入AVFoundation/AVFoundation.h

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆