didSelectRowAt indexPath 播放音频
didSelectRowAt indexPath play Audio
我需要你的帮助!我正在使用 Jukebox API 开发音频播放器应用程序。我正在使用 didSelectRowAt indexPath 播放当前流。我的代码有效,但它不会在单击另一个带有单元格的播放之前停止流。我将不胜感激任何帮助!谢谢!
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
jukebox = Jukebox(delegate: self as? JukeboxDelegate, items: [
JukeboxItem(URL: NSURL(string:audio_url[indexPath.row])! as URL)
])
jukebox.play()
}
试试看
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
stopJukeBox()
jukebox = Jukebox(delegate: self as? JukeboxDelegate, items: [
JukeboxItem(URL: NSURL(string:audio_url[indexPath.row])! as URL)
])
playJukeBox()
}
func stopJukeBox(){
if jukebox != nil {
jukebox.stop()
}
}
func playJukeBox(){
if jukebox != nil {
jukebox.play()
}
}
或者直接在didSelect函数中处理play和stop
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Stop
if jukebox != nil {
jukebox.stop()
}
jukebox = Jukebox(delegate: self as? JukeboxDelegate, items: [
JukeboxItem(URL: NSURL(string:audio_url[indexPath.row])! as URL)
])
// play
if jukebox != nil {
jukebox.play()
}
}
我需要你的帮助!我正在使用 Jukebox API 开发音频播放器应用程序。我正在使用 didSelectRowAt indexPath 播放当前流。我的代码有效,但它不会在单击另一个带有单元格的播放之前停止流。我将不胜感激任何帮助!谢谢!
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
jukebox = Jukebox(delegate: self as? JukeboxDelegate, items: [
JukeboxItem(URL: NSURL(string:audio_url[indexPath.row])! as URL)
])
jukebox.play()
}
试试看
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
stopJukeBox()
jukebox = Jukebox(delegate: self as? JukeboxDelegate, items: [
JukeboxItem(URL: NSURL(string:audio_url[indexPath.row])! as URL)
])
playJukeBox()
}
func stopJukeBox(){
if jukebox != nil {
jukebox.stop()
}
}
func playJukeBox(){
if jukebox != nil {
jukebox.play()
}
}
或者直接在didSelect函数中处理play和stop
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Stop
if jukebox != nil {
jukebox.stop()
}
jukebox = Jukebox(delegate: self as? JukeboxDelegate, items: [
JukeboxItem(URL: NSURL(string:audio_url[indexPath.row])! as URL)
])
// play
if jukebox != nil {
jukebox.play()
}
}