AVAudioPlayer关闭iPod - 如何解决? [英] AVAudioPlayer turns off iPod - how to work around?

查看:111
本文介绍了AVAudioPlayer关闭iPod - 如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AVAudioPlayer在我的应用程序中播放声音,但在声音播放时关闭iPod。



有没有办法防止这种情况?我不想使用System Sounds,因为我无法控制音量。



感谢您的帮助。

  [h2_lin]>解决方案

[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
UInt32 doSetProperty = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers,sizeof(doSetProperty),& doSetProperty);
[[AVAudioSession sharedInstance] setActive:YES error:nil];

从文件:


kAudioSessionProperty_OverrideCategoryMixWithOthers
更改
kAudioSessionCategory_MediaPlayback

kAudioSessionCategory_PlayAndRecord
音频会话类别的混合行为。将
属性设置为TRUE(任何非零值)
允许将iPod音频与
应用程序音频混合。
这些类别的其他方面,例如他们的
Ring / Silent开关行为,不受
影响。



此属性具有值默认为FALSE(0)
。当音频会话
类别更改时,例如在
中断期间,此
属性的值将恢复为FALSE。要重新获得
混合行为,必须重新设置
此属性。



始终检查设置此
属性是否成功或失败,并适当地反应
;



可在iPhone OS 3.0及更高版本中使用。



在AudioServices.h中声明。



I use AVAudioPlayer to play sounds in my app, but it turns off the iPod when a sound plays.

Is there a way to prevent this? I don't want to use System Sounds because I can't control their volume.

Thanks for your help.

解决方案

This should work for you (taken from my Ambiance app)

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
UInt32 doSetProperty = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
[[AVAudioSession sharedInstance] setActive: YES error: nil];

From the docs:

kAudioSessionProperty_OverrideCategoryMixWithOthers Changes the mixing behavior of the kAudioSessionCategory_MediaPlayback and kAudioSessionCategory_PlayAndRecord audio session categories. Setting this property to TRUE (any nonzero value) allows mixing of iPod audio with application audio. Other aspects of these categories, such as their Ring/Silent switch behavior, are not affected.

This property has value of FALSE (0) by default. When the audio session category changes, such as during an interruption, the value of this property reverts to FALSE. To regain mixing behavior you must then re-set this property.

Always check to see if setting this property succeeds or fails, and react appropriately; behavior may change in future releases of iPhone OS.

Available in iPhone OS 3.0 and later.

Declared in AudioServices.h.

这篇关于AVAudioPlayer关闭iPod - 如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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