最近在学习android边学边做个小例子 是个MP3plaer在写动态歌词和进度条的时候有点问题歌词我是用handler 在service中处理后广播给activity 进行textview的更新进度条是我在service中起了个新线程不断刷新activity中的seekbaractivity中的seekbar是public的调试的时候发现seekbar是在动  歌词却不更新了求原因

解决方案 »

  1.   

    sorry 昨晚发帖发的太急了
    这个是我处理歌词的class UpdateTimeCallBack implements Runnable{ ArrayList<LrcInfo> list=null; public UpdateTimeCallBack(ArrayList<LrcInfo> list) {
    this.list=list;
    } @Override
    public void run() {
    //该偏移量表示从开始播放一首MP3到现在为止,一共消耗了多少时间,以毫秒为单位
    long offset=System.currentTimeMillis()-beginMusic;
    if (currentTimeMill==0) {//第一次播放
    LrcInfo lrcInfo=list.get(0);
    nextTimeMill=lrcInfo.getTimeMill();
    message=lrcInfo.getWords();
    index++;
    }


    if (offset>=nextTimeMill) {//当前时间超过下一条歌词要播放的时间
    //这里是发送一个Intent给PlayActivity,通知其更新歌词
    Intent intent=new Intent();
    intent.setAction(AppConstant.LRC_MESSAGE_ACTION);
    intent.putExtra("lrcMessage", message);
    sendBroadcast(intent); if (index!=list.size()) {
    LrcInfo lrcInfo=list.get(index);
    message=lrcInfo.getWords();
    nextTimeMill=lrcInfo.getTimeMill();
    index++;
    currentTimeMill+=5;
    handler.postDelayed(updateTimeCallBack, 5);
    }

    else {
    stop();
    }


    }

    }
    这个是我处理进度条的,这个类我放在service中 new Thread(new RefreshSeekBar()).start(); class RefreshSeekBar implements Runnable{ @Override
    public void run() {
    int currentPosition = 0;// 设置默认进度条当前位置  
            int total = mediaPlayer.getDuration();//  
            while (mediaPlayer != null && currentPosition < total) {  
                try {  
                    Thread.sleep(1000);  
                    if (mediaPlayer != null) {  
                        currentPosition = mediaPlayer.getCurrentPosition();  
                    }  
                } catch (InterruptedException e) {  
                    e.printStackTrace();  
                }  
                PlayerActivity.seekBar.setProgress(currentPosition);  
            }  

    }

    }
    调试的结果是 进度条在动 但是歌词的textview不更新,断点看了下 歌词是取了出来  setText方法也是执行的 
    奇怪的是我每次暂停的时候他就更新歌词了。。