@Override public void run() { while (true) { if (musicUpdateListener != null && mediaPlayer != null && mediaPlayer.isPlaying()) { musicUpdateListener.onPublish(getCurrentProgress()); } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } }
// 播放 public void play(int position) { if (position >= 0 && position < mp3Infos.size()) { Mp3Info mp3Info = mp3Infos.get(position); try { mediaPlayer.reset(); mediaPlayer.setDataSource(this, Uri.parse(mp3Info.getUrl())); mediaPlayer.prepare(); mediaPlayer.start(); currentPosition = position; } catch (IOException e) { e.printStackTrace(); } if (musicUpdateListener != null) { musicUpdateListener.onChange(currentPosition); } } }