gpt4 book ai didi

ios - didSelectRowAt indexPath 播放音频

转载 作者:可可西里 更新时间:2023-11-01 02:02:07 24 4
gpt4 key购买 nike

我需要你的帮助!我正在使用 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()
}

}

关于ios - didSelectRowAt indexPath 播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45538515/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com