ios - Swift 中的 AudioToolBox - 声音在模拟器中有效,但在我的 iPad 上无效

标签 ios swift ipad audio audiotoolbox

我正在创建一个音乐应用程序,其中不同的铃声将在节奏周期的不同点播放。到目前为止,我的代码在模拟器中运行良好,但我的设备上没有任何声音。我从其他应用程序获得声音。我的代码有问题吗?谢谢你的帮助!

import UIKit
import AudioToolbox

func playChime1() {
    var chime1URL: NSURL?
    var chime1ID:SystemSoundID = 0
    let filePath = NSBundle.mainBundle().pathForResource("Chime", ofType: "mp3")
    chime1URL = NSURL(fileURLWithPath: filePath!)
    AudioServicesCreateSystemSoundID(chime1URL!, &chime1ID)
    AudioServicesPlaySystemSound(chime1ID)
}
func playChime2() {
    var chime2URL: NSURL?
    var chime2ID:SystemSoundID = 0
    let filePath = NSBundle.mainBundle().pathForResource("Chime2", ofType: "mp3")
    chime2URL = NSURL(fileURLWithPath: filePath!)
    AudioServicesCreateSystemSoundID(chime2URL!, &chime2ID)
    AudioServicesPlaySystemSound(chime2ID)
}
func playChime3() {
    var chime3URL: NSURL?
    var chime3ID:SystemSoundID = 0
    let filePath = NSBundle.mainBundle().pathForResource("Chime3", ofType: "mp3")
    chime3URL = NSURL(fileURLWithPath: filePath!)
    AudioServicesCreateSystemSoundID(chime3URL!, &chime3ID)
    AudioServicesPlaySystemSound(chime3ID)
}

最佳答案

我遇到了同样的问题,意识到我的 iPhone 处于静音模式,将其关闭以静音播放声音。

不幸的是,AudioToolbox 的声音响应设备的“铃声”音量,而不是音频通过 AVFoundation 使用的“音量”设置。

这是有道理的,因为 AudioToolbox 应该用于系统声音。

关于ios - Swift 中的 AudioToolBox - 声音在模拟器中有效,但在我的 iPad 上无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35966108/

相关文章:

ios - App Store Connect 屏幕截图的尺寸

javascript - 在 iOS Chrome 中返回页面时恢复表单值

ios - 如何使用 SocketIO 订阅套接字 channel ?

ipad - jQuery Mobile 响应式面板和 Textarea

objective-c - 当手放在 iPad 屏幕上时,如何仅检测一次触摸?

android - Flutter中如何从外部存储获取文件?

重新加载 JS 时,iOS React Native 应用程序在 JSCExecutor.cpp 中崩溃

ios - “<...> 不是有效的 NSFetchRequest。”

ios - 如何在 FSCalendar 中获取月份

objective-c - 你能阻止人们在 iPad 1 上使用你的应用程序吗?