- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我遵循了关注我的扬声器状态的方法:
AudioSession.h
enum {
kAudioSessionOverrideAudioRoute_None = 0,
kAudioSessionOverrideAudioRoute_Speaker = 'spkr'
};
我的类(class)
@synthesize speakerEnabled;
...
- (void)setSpeakerEnabled:(BOOL)enable {
speakerEnabled = enable;
if(enable) {
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute
, sizeof (audioRouteOverride)
, &audioRouteOverride);
} else {
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute
, sizeof (audioRouteOverride)
, &audioRouteOverride);
}
}
但是它仅适用于 iPhone,对于 iPad - 没有任何反应。
当我按下按钮:Speaker On
时,我进入 if(enable)
并且 AudioSessionSetProperty
收到 kAudioSessionOverrideAudioRoute_Speaker
;
当我按下按钮:Speaker Off
时,我进入 else
并且 AudioSessionSetProperty
收到 kAudioSessionOverrideAudioRoute_None
;
我开始调试,但没有发现设备之间的区别。
我有 iPad2 iOS 6.1。
我错过了什么吗?
请帮帮我
编辑
正如 LombaX 所说,我在启动应用程序时添加了 AVAudioSession
类别:
NSError *err = nil;
BOOL success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&err];
if(!success){
[MyLogger logc:MyLoggerLog format:"%@",[err localizedDescription]];
}
成功 = 是
还是不行。
最佳答案
我认为您误解了此属性的用途。您希望启用/禁用扬声器。这不是 kAudioSessionProperty_OverrideAudioRoute
的意图。相反,它会以相当有限的方式影响输出声音路由。
这些是 iPhone 可用的各种可能的输出路径
extern const CFStringRef kAudioSessionOutputRoute_LineOut
extern const CFStringRef kAudioSessionOutputRoute_Headphones
extern const CFStringRef kAudioSessionOutputRoute_BluetoothHFP
extern const CFStringRef kAudioSessionOutputRoute_BluetoothA2DP
extern const CFStringRef kAudioSessionOutputRoute_BuiltInReceiver
extern const CFStringRef kAudioSessionOutputRoute_BuiltInSpeaker
extern const CFStringRef kAudioSessionOutputRoute_USBAudio
extern const CFStringRef kAudioSessionOutputRoute_HDMI
extern const CFStringRef kAudioSessionOutputRoute_AirPlay
这些只是可能的路线 - 实际可用的路线取决于上下文。 Apple 严格限制您在应用程序内确定这些路线的能力,因为用户需要以设备一致的方式控制这些路线。它们中的大多数是由用户插入/拔出硬件(耳机、USB、HDMI、线路输出)隐式确定的,Apple 不希望您的应用在这里扰乱用户的期望。
如果媒体上下文正确(并且 airplay 可用),可以使用 MPVolumeView
的 routeButton
选择 Airplay。蓝牙可以由 OverrideCategoryEnableBluetoothInput
( which controls both input and output )
请特别注意,kAudioSessionOutputRoute_BuiltInReceiver
是您在打电话时放在耳边的 iPhone 上的低电平扬声器。如果没有插入外部设备(例如耳机),这是 iPhone 的默认音频输出路径。kAudioSessionOutputRoute_BuiltInSpeaker
是手机底部的“免提”扬声器。
您可以通过设置以下覆盖属性之一从当前默认值重新路由到此 BuiltInSpeaker
:
key: kAudioSessionProperty_OverrideAudioRoute
values: kAudioSessionOverrideAudioRoute_Speaker
: kAudioSessionOverrideAudioRoute_None
Specifies whether or not to override the audio session category’s normal audio route.
key: kAudioSessionProperty_OverrideCategoryDefaultToSpeaker
values: TRUE
: FALSE
Specifies whether or not to route audio to the speaker (instead of to the receiver) when no other audio route, such as a headset, is connected.
这两个仅设计用于 kAudioSessionCategory_PlayAndRecord
Audio Session 类别。
请注意,在这两种情况下,您都没有在任何输出路径中进行选择,您只是覆盖了“默认路径”以支持内置(大声)扬声器。
没有电话的 iPad 没有 BuiltInReceiver
类型的扬声器。在没有连接的小工具或 airplay 的情况下,它的默认路径是完全相同的 BuiltInSpeaker
。因此,重写没有任何效果。
假设您真的想在您的应用中使音频静音,您如何实现这一点取决于您的应用设计的许多其他方面。如果您想使设备静音,Apple 宁愿用户通过响铃/静音开关来控制它。似乎他们不会有任何其他方式:
I've had a response from Apple on this. They've said they don't and never have provided a method for detecting hardware mute switch and don't intend to do so. https://stackoverflow.com/a/8009073/1375695
“扬声器设置是对设备的覆盖,而不是对给定声音的覆盖”
http://lists.apple.com/archives/coreaudio-api/2009/Mar/msg00300.html
关于ios - 无法控制 iPad 上的扬声器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16230831/
我妻子有一台 iPad,我想知道我是否可以用它来开发 iPad 应用程序?我假设答案是否定的。 最佳答案 Apple 的开发指南禁止商店中的此类应用程序,因此不幸的是,您不能使用 iPad 来制作 i
我开发了一个 iPad 应用程序,并为应用程序商店制作了分发配置文件,我需要在 30 台 iPad 上安装我开发的应用程序以进行一次事件,但我无法安装。我收到错误消息:(应用程序“xxxx”未安装在
我正在佛罗里达州开发一款 iPad/iPhone 应用程序,希望纽约的同事能帮我测试一下。纽约的测试人员没有 iMac,因为他们不在该地点进行任何开发。我只是想让他们验证他们所在位置的操作。有什么方法
我可以检测用户(音乐家)手指施加的力或压力吗? 最佳答案 还没有。 有一个技术演示展示了如何做到这一点。见 http://tenonedesign.com/blog/pressure-sensitiv
浏览器分辨率是多少?我已经在谷歌上搜索了一段时间,但不知何故我找不到它! 最佳答案 960x768 或 704x1024 关于ipad - iPad 的屏幕尺寸减去浏览器中的地址栏是多少?,我们在St
我的应用只能在横向使用,并且只能在横向启动。因此,iPad为横向时,左上角为(0,0),因此一切正常。 但是,当我拿起“ touchesBegan” ...时,它无法正常工作。只有当我像正确的三分之二
我在 ionic 中创建输入,它只接受数字。这适用于除 safari 和 ipad 之外的所有浏览器和设备。我不希望用户输入数字以外的任何内容。我尝试对输入事件进行正则表达式验证,但这并不能阻止用户输
是否可以在 iPad 中显示仅包含 0-9 数字的键盘?,我不希望键盘显示任何其他内容。我知道有这个 键盘类型:数字键盘 我们可以在 .xib 文件中,但它显示所有其他额外的字符,包括数字。我想使用这
我正在做一个SproutCore项目。我试图按原样在IPAD上获取该站点,但是CSS背景图像,onClick和重定向在IPAD上不起作用。 让我知道对此的任何解决方案。 最佳答案 在iPad上进行开发
我已经设置了MFMailComposeViewController,它在iPhone上正常工作,但是在iPad上崩溃了,并说: *** Terminating app due to uncaught
iPad:遍历UITableView中的每个单元格吗? 最佳答案 for (int section = 0; section < [tableView numberOfSections]; secti
我在这里寻找两个数字:纵向高度和横向高度。不要以厘米或英寸为单位回答,而以像素为单位。 最佳答案 纵向高度为 264,横向高度为 352。 我知道这是一个迟到的答案,但我自己也遇到了这个问题。 关于i
在我的应用程序中,我想播放Youtube URL(ipad)。我正在使用下面的代码。它只是向我显示一个白色屏幕 YouTube网址是:http://www.youtube.com/watch?v =
据我所知,iPad 使用 iPhone 操作系统,但屏幕分辨率与 iPhone 和 iPod touch 不同。许多网站可能必须更改其用户代理检测以适应 iPad。 那么,任何有权访问 iPad 或
我想预加载多个音频文件。为此,我尝试在JavaScript中创建多个Audio元素。 function loadAudio(){ audio1 = new Audio(); audio
我想使用适用于在所有最新 iPad 上查看的网页的字体。我找到了给定版本的 IOS 附带的字体列表。但这不是我想要的。我更喜欢给定 iPad 实际附带的字体列表,而不是 IOS 版本。如何解决这个问题
是否有可能拥有一个不在应用商店上架的 iPad 单独应用。该应用程序将在某些选定的成员中使用。因此它不需要进入应用商店,因为它不是供公众使用的。 最佳答案 那么有一些众所周知的可能性: Ad Hoc
子像素字体渲染如 ClearType显着提高字体显示分辨率并提高屏幕可读性。我如何对字体的子像素渲染进行编程(一般而言),以及如何在 iPad 上实现这一点(iOS 设备上的 C、C++ 或 Obje
我正在为 9.7 英寸 iPad 设计一个应用程序。我想知道是否有人对为更大的 iPad 设计的应用程序在 iPad mini 上的外观有任何经验?它会自动缩小,以某种方式在较小的屏幕上完美使用吗?还
我正在使用所有 UIKit,并且出于原型(prototype)设计的目的,我刚刚将所有逻辑插入了主 viewController。我在 viewDidLoad 中创建了一些 UIView,隐藏了一些,
我是一名优秀的程序员,十分优秀!