2017-08-07 13 views
2

私はあなたの助けが必要です!私はJukebox APIを使ってAudio Playerアプリケーションを開発しています。私は現在のストリームを再生するためにdidSelectRowAt indexPathを使用しています。私のコードは動作しますが、セルを持つ別のものを再生する前にストリームを停止しません。私はどんな助けにも感謝しています!ありがとう!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() 

} 

答えて

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

を参照するか、あなたは直接プレイを処理し、

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

} 
+0

は完全に働いたdidSelect機能で停止することができます!本当にありがとう! – theappledev

関連する問題