मैं एक साधारण ध्वनि ऐप बनाने की कोशिश कर रहा हूं। मैं एक क्लिप को एक ध्वनिबोर्ड की तरह एक क्लिप चलाने के लिए दबाता हूं। समस्या यह है कि जब मैं इसे बनाने के लिए जाता हूं तो कहता है कि "ViewController" में कोई प्रारंभिक नहीं हैवर्ग "व्यू कंट्रोलर" के पास कोई प्रारंभिक नहीं है
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer: AVAudioPlayer
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func playSound(sender:UIButton){
// Set the sound file name & extention
let audioFilePath = Bundle.main.path(forResource: "emp_learntoknow", ofType: "mp3")
if audioFilePath != nil {
let audioFileUrl = URL.init(fileURLWithPath: audioFilePath!)
do {
audioPlayer = try AVAudioPlayer(contentsOf: audioFileUrl)
audioPlayer.play()
} catch {
print("audio file is not found")
}
}
}
आपको बस जोड़ना होगा: 'var audioplayer: AVAudioPlayer? = शून्य –