【问题标题】:didSelectRowAt indexPath play AudiodidSelectRowAt indexPath 播放音频
【发布时间】:2017-08-07 02:12:00
【问题描述】:

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

 }

【问题讨论】:

    标签: ios swift uitableview audio-player


    【解决方案1】:

    试试这个看看

    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 函数中处理播放和停止

    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()
       }
    
    }
    

    【讨论】:

    • 完美运行!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多