[ad_1]
//Here is My Code >>>
import UIKit
import AVFoundation
import PianoKeyboard
class PianoViewController: UIViewController{
@IBOutlet weak var pianoKeyboard: PianoKeyboard!
@IBOutlet weak var fullMiniPianoView: UIView!
var participant: AVAudioPlayer?
override func viewDidLoad() {
tremendous.viewDidLoad()
pianoKeyboard.delegate = self
}
open override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
get {
return .landscapeRight
}
}
func playSound(fileName: String) {
guard let path = Bundle.principal.path(forResource: fileName, ofType: "mp3") else {
return }
let url = URL(fileURLWithPath: path)
do {
participant = strive AVAudioPlayer(contentsOf: url)
participant?.play()
} catch let error {
print(error.localizedDescription)
}
}
}
extension PianoViewController: PianoKeyboardDelegate{
func pianoKeyUp(_ keyNumber: Int) {
}
func pianoKeyDown(_ keyNumber: Int) {
playSound(fileName: "key" + String(format: "%02d", keyNumber+1))
}
}
[ad_2]
