Мой проект воспроизводит музыку c нажатием кнопки воспроизведения! Мне нравится, что мой проект может быть умным, чтобы обнаружить кнопку воспроизведения с наушников Bluetooth для воспроизведения песни! Что мне делать?
Это мой код:
import UIKit
import AVFoundation
var player = AVAudioPlayer ()
class ViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
}
@IBAction func playButton_Action(_ sender: UIButton)
{
do
{
if let audioPath = Bundle.main.path(forResource: "music", ofType: "mp3")
{
let audioURL = URL(fileURLWithPath: audioPath)
player = try AVAudioPlayer(contentsOf: audioURL)
player.prepareToPlay()
player.play()
}
}
catch
{
print("Error")
}
}
}