本文介绍了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];

从文件:


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:

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

09-17 21:56