if let url = NSBundle.mainBundle().URLForResource("SomeAudioFile", withExtension: "m4a") {
player.removeAllItems()
player.insertItem(AVPlayerItem(URL: url), afterItem: nil)
player.play()
} else {
print("Go to your Build Phases/Copy Bundle Resources to make sure that your music file IS INDEED there. If not, drag it from the Navigator pane into the Copy Bundle Resources folder.")
}
3条答案
按热度按时间jchrr9hc1#
下面是一些代码:
雨燕3
雨燕2
您没有解释如果多次点击该按钮会发生什么,所以我假设您希望停止正在播放的当前项目,并开始一个新的项目。
hmmo2u0o2#
2nbm6dog3#
Swift 5更新: