ボタンが1つしかない単純なプログラムがあり、その唯一の機能はサウンド出力をトリガーすることです。Swift 3 - AVAudioPlayerがサウンドを再生していません
iOSシミュレータでテストするとアプリは完璧に動作しますが、iPhoneでテストすると、アプリはサウンドを再生していません。私は2つの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のあなたの音量レベル(未着信音) – Alex