すいません。。。お手上げなので質問させていただきます。
単純にボタンを押して音が出るー音を消すアプリを作成中なのですが、
題名のエラーが出て解決できません。
やってみたこと
- Outlets接続の確認。再設定。
ソースは下記です。
Swift
1import UIKit 2import AVFoundation 3 4class ViewController: UIViewController { 5 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 // Do any additional setup after loading the view, typically from a nib. 10 fire.isHidden = true 11 12 } 13 14 let gokiPath = Bundle.main.bundleURL.appendingPathComponent("test.mp3") 15 var gokiPlayer = AVAudioPlayer() 16 17 18 19 @IBOutlet weak var fire: UIImageView! 20 @IBOutlet weak var playOrStop: UILabel! 21 22 23 @IBAction func goki(_ sender: Any) { 24 25 do{ 26 gokiPlayer = try AVAudioPlayer(contentsOf: gokiPath, fileTypeHint: nil) 27 gokiPlayer.numberOfLoops = -1 28 29 fire.isHidden = false 30 gokiPlayer.play() 31 playOrStop.text = "Ringing" 32 33 34 }catch{ 35 36 } 37 } 38 39 40 @IBAction func off(_ sender: Any) { 41 42 gokiPlayer.pause() 43 // gokiPlayer.currentTime = 0 44 fire.isHidden = true 45 playOrStop.text = "Stopping" 46 47 } 48 49 50} 51 52
どのアクションの際にエラーが出てますか?
viewが表示された時? or ボタンを押した時?
あなたの回答
tips
プレビュー