gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 23:00:41 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com