【发布时间】:2016-10-11 20:53:44
【问题描述】:
我有一个简单的程序,它只有一个按钮,唯一的功能是触发声音输出。
该应用程序在 iOS 模拟器上测试时运行良好,但当我在 iPhone 上测试时,该应用程序没有播放任何声音。我已经在两部 iPhone 上对此进行了测试。
这从前是有效的。我不知道更新到 iOS 10 是否导致了这个问题。
这是我的代码:
//Code
import UIKit
import AVFoundation
var audioPlayer = AVAudioPlayer()
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let music = Bundle.main.path(forResource: "sound", ofType: "wav")
do {
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: music! ))
}
catch{
print(error)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func playSound(_ sender: UIButton) {
audioPlayer.play()
}
}
如果有任何答案,将不胜感激。 谢谢。
【问题讨论】:
-
请检查您的 iPhone 音量(不是铃声)
标签: ios iphone swift audio swift3