0

在我的应用程序中,我正在使用媒体播放器,我想在那里放置一个搜索栏。在我的代码中,歌曲正在播放,但搜索栏没有移动。以下是我的代码的一部分...

sv = (SurfaceView)findViewById(R.id.surfaceView1);
sv.postDelayed(runnable,200);  

 final Runnable runnable = new Runnable()
        {
            @Override
            public void run() 
            {
                if (mediaPlayer != null) 
                {
                    if (isPlaying) 
                    {
                        try 
                        {
                           int currentPosition = mediaPlayer.getCurrentPosition();

                            audioProgress.setProgress((int) ((currentPosition / (float) mediaPlayer.getDuration()) * 100f));

                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        sv.postDelayed(runnable, 150);
                    }
                }
            }

        };

请任何人帮助我清除错误...

4

1 回答 1

1

对您的代码进行以下更改:

sv = (SurfaceView)findViewById(R.id.surfaceView1);
audioProgress.setMax(mediaPlayer.getDuration()); // this is one change
sv.postDelayed(runnable,200);  

 final Runnable runnable = new Runnable()
        {
            @Override
            public void run() 
            {
                if (mediaPlayer != null) 
                {
                    if (isPlaying) 
                    {
                        try 
                        {
                           int currentPosition = mediaPlayer.getCurrentPosition();

                                // the other change:
                    audioProgress.setProgress(currentPosition);

                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        sv.postDelayed(runnable, 150);
                    }
                }
            }

        };
于 2011-05-12T12:41:03.450 回答