AVAudioPlayer关闭iPod

编程入门 行业动态 更新时间:2024-10-09 23:12:39
本文介绍了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

本文发布于:2023-11-25 09:22:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629200.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AVAudioPlayer   iPod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!