2012-01-19 71 views
0

在m中使用android seekbar with play和剩余时间为songprgress处理程序的线程以下示例代码。每当我点击下一首/上一首歌曲时,它会显示大整数值。如何解决这个问题?seekbar播放时间和剩余时间显示大整数值。

class SongProgressUpdateThread extends Thread { 
    public void run() { 

     if (mp != null) { 
      int currentPosition = 0; 
      int total = mp.getDuration(); 
      while (currentPosition < total && mp.isPlaying() && stopSongProgressThread==false) { 
       try { 
        Thread.sleep(500); 
        currentPosition = mp.getCurrentPosition(); 
       } catch (InterruptedException e) { 
        return; 
       } catch (Exception e) { 
        return; 
       } 
       songProgress.setProgress(currentPosition); 
       showProgress(currentPosition, total); 
      } 

     } 
    } 
} 





private void showProgress(int currentPosition, int duration) { 
    Bundle bundle = new Bundle(); 
    bundle.putString("playedTime", getPlayedTime(currentPosition)); 
    bundle.putString("remainingTime",getRemainigTime(currentPosition, duration)); 
    Message msg = new Message(); 
    msg.setData(bundle); 
    songProgresshandler.sendMessage(msg); 
} 

Handler songProgresshandler = new Handler() { 
    public void handleMessage(Message message) { 
     final Bundle b = message.getData(); 
     playedTime.setText(b.getString("playedTime")); 
     remainingTime.setText("-" + b.getString("remainingTime")); 
    } 
}; 
+0

请粘贴您的getPlayedTime()和getRemainingTime实现 – jeet

+0

请注意,您可以[将行格式化为代码](http://meta.stackexchange.com/questions/22186/)缩进四个空格。编辑器工具栏中的“{}”按钮可以为您做到这一点。编辑你的问题并尝试一下。单击编辑器工具栏中的橙色问号以获取更多信息和格式化提示。 – outis

+0

请用请求的代码更新问题。一般而言,通过更新您的帖子来回应澄清请求,而不是回复评论。首先,如果没有阅读评论,一个问题应该是可以理解的。另一方面,SO是一个质量保证和网站,而不是一个论坛,评论意图不适合(也不适合)讨论。 – outis

回答

0

也许你可以尝试使用VideoView和MediaController来做到这一点。 如:

VideoView vv = (VideoView)this.findViewById(R.id.videoview); 
Uri uri = Uri.parse(path); 
MediaController mediaController = new MediaController(this); 
mediaController.setMediaPlayer(vv); 
vv.setVideoURI(uri); 
vv.setMediaController(mediaController); 
vv.start(); 
mediaController.show(); 
0

你做了什么时,单击下一步/上一页按钮 也许MediaPlayer正在下一个无效的状态,看logcat的任何错误消息(如“getDuration()无效的状态,请执行” )