I use AVMIDIPlayer to play music, some devices do not have sound, click System Settings > general purpose > restore to solve. What is the reason for this?
import UIKit
import AVKit
class ViewController: UIViewController {
var avplayer : AVMIDIPlayer?
override func viewDidLoad() {
super.viewDidLoad()
let filePatch = Bundle.main.path(forResource: "xiaobuwuqu", ofType: "mid")
let sfTowPatch = Bundle.main.path(forResource: "TimGM6mb", ofType: "sf2")
let data = try? Data(contentsOf: URL(fileURLWithPath: filePatch!))
avplayer = try? AVMIDIPlayer(data: data!, soundBankURL: URL(fileURLWithPath: sfTowPatch!))
avplayer?.prepareToPlay()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
avplayer?.currentPosition = 0
avplayer?.play({
})
print(avplayer?.isPlaying)
}
}