- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我尝试了类似问题的各种解决方案,但无法让我的代码正常工作。我在我的应用程序中调用了以下函数:
func PlaySound (WhenToPlaySound:String) {
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
if WhenToPlaySound == "BeginningOfRound" {
if UIApplication.sharedApplication().applicationState == UIApplicationState.Background {
soundnotification.soundName = "BoxingBellStart.wav"
UIApplication.sharedApplication().scheduleLocalNotification(soundnotification)
println("timer is done in background mode")
} else {
// Load Sound
soundlocation = NSBundle.mainBundle().URLForResource("BoxingBellStart", withExtension: "wav")!
player = AVAudioPlayer(contentsOfURL: soundlocation, error: &Error)
player.volume = 1.0
// Play Sound
player.play()
println("timer is done in active mode")
}
} else {
if UIApplication.sharedApplication().applicationState == UIApplicationState.Background {
soundnotification.soundName = "Boxing.wav"
UIApplication.sharedApplication().scheduleLocalNotification(soundnotification)
println("timer is done in background mode")
} else {
// Load Sound
soundlocation = NSBundle.mainBundle().URLForResource("Boxing", withExtension: "wav")!
player = AVAudioPlayer(contentsOfURL: soundlocation, error: &Error)
player.volume = 1.0
// Play Sound
player.play()
println("timer is done in active mode")
}
}
}
除了两件事,它大部分都有效:
<罢工>1。我似乎无法覆盖扬声器音量。我希望在播放声音之前将系统音量调到最大。
为了解决第一个问题,我想做以下但不知道如何使用它:
AVAudioSession.sharedInstance().overrideOutputAudioPort(<#portOverride: AVAudioSessionPortOverride#>, error: <#NSErrorPointer#>)
提前致谢,艾斯
最佳答案
overrideOutputAudioPort
影响音频路由,而不是音量。
当您说您想要“覆盖扬声器音量”时,我假设您的意思是您想要通过应用程序代码控制系统输出音量。这是不可能的,因为 Apple 认为输出音量应始终由用户控制。
AVAudioPlayer 的 volume
属性将音量相对设置为系统输出级别。默认为 1.0(播放器音量 == 系统音量)。你不能把它调高,像脊椎穿刺一样,到 1.1...
另请参阅我的回答 here ...如果你想控制系统音量,你将需要 MPVolumeView 提供的用户界面。
与您的通知类似 - 如果用户将设备静音,您的应用将无法忽略它。
更新
关于通知,它并不像我建议的那么简单。如果您将 AVAudioSession 类别设置为 AVAudioSessionCategoryPlayback
(和 read the apple docs on this setting ),它可能会起作用。
When using this category, your app audio continues with the Silent switch set to silent or when the screen locks
您可能还需要将“音频”添加到 info.plist
中的 UIBackgroundModes
。
关于ios - AVAudioSession overrideOutputAudioPort & localNotifications 静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28901374/
我正在 XCode 6 中测试我的应用程序,并发现 iOS8 中的 AVAudioSession 存在问题。 当我打电话时 [[AVAudioSession sharedInstance] setAc
在我的相机 View Controller 的 viewWillAppear 方法中,我将 Audio Session 的类别设置为录制并将其设置为事件状态。在其 viewWillDisappear
如果 iPhone 连接了多个输入和输出附件,我希望用户能够手动选择输入和输出源。我可以通过查询 [[AVAudioSession sharedInstance] availableInputs] 手
我正在编写一个播放背景音乐的应用程序,为此我使用 AVAudioSession ,如下所示: [[AVAudioSession sharedInstance] setCategory:AVAudioS
我使用 AVSoundSession 来配置声音,并使用 AVAudioPlayer 来播放不同的声音。我搜索了很多,但没有找到任何东西。如何操作输出源? 我的 SoundManager 中需要一个方
我有一个可以显示视频的应用,我想要以下行为。 当视频首次出现在屏幕上并开始播放时,它的音频应该与可能已经在播放的其他应用的音频混合在一起。例如,如果用户正在收听 Spotify,他们应该听到来自 Sp
在我的 iOS 应用程序中,我正在像这样注册到 AVAudioSession 中断通知 [[NSNotificationCenter defaultCenter] addObserver:self s
我知道关于 AVAudioSession 也有类似的问题,但我的有点不同。我有 AVAudioSession 中断的问题。 拒绝通话后,它会恢复,但它只保存中断后录制的部分 - 通话前的部分就消失了。
我正在使用 AVAudioSession 来收听语音输入。它适用于有线耳机,但不适用于连接的蓝牙设备。以下是我用来设置蓝牙麦克风输入的代码 func setupSessionForRecording(
对于我正在制作的应用程序的一部分,我需要录制用户的音频。我已选择使用 AVAudioRecorder 来执行此操作。 问题是当我开始录制音频时,设备上播放的所有音频都暂停了。然后,我查看了 AVAud
我正在尝试在我的 Swift SpriteKit 应用程序中使用 AVAudioSession。我遇到了奇怪的“未声明类型”问题。例如…… import AVFoundation var audioS
我有一个应用程序使用 AVAudioSession 和 AVAudioSessionCategoryPlayAndRecord 来捕获麦克风输入。我正在寻找将高通(可能还有其他)滤波器应用于捕获的音频
我试图在通话期间模仿电话应用程序中的行为。您可以轻松地将输出源从/切换到扬声器或耳机。我知道当通过调用连接耳机时我可以强制扬声器作为输出: try! audioSession.setCategory(
我收到以下错误,但不知道是什么原因造成的。 Aug 4 15:04:56 MyiPad myApp[1523] : 15:04:56.072 ERROR: [0x78ba000] AVAudioSes
我在蓝牙播放方面遇到问题,但仅限于某些蓝牙设备。其他应用程序在这些相同的蓝牙设备上运行良好。我为 AVAudioSession 设置类别的方式是否遗漏了什么? let session = AV
嘿,下面是这段代码。我只是想得到它,以便如果他们是任何音乐、播客等正在从操作系统内的另一个应用程序播放,所有声音都会被静音。但是我已经尝试设置它的类别,但它不起作用!我没有使用正确的类别吗?也许不在正
在 iOS 中,我试图在播放某些音效时隐藏音乐应用程序的音乐。如果您不知道,“闪避”只是指在播放我的声音之前音乐音量降低一点,然后播放声音,然后音乐音量恢复到初始音量。 对于回避,我将 AVAudio
我想配置 AVAudioSession 以便我可以录制带音频的视频并播放音乐应用程序(或任何其他产生声音的应用程序,通常是互联网 radio 应用程序)中的音乐 我这样配置 session : try
我正在使用以下代码来检测可用的输出,但它没有接收到我连接的蓝牙设备。我知道我的蓝牙设备已正确连接,因为我正在用它播放音乐。 let session = AVAudioSession.sharedIns
我收到以下错误: [0x19bf89310] AVAudioSession.mm:646: -[AVAudioSession setActive:withOptions:error:]: Deacti
我是一名优秀的程序员,十分优秀!