Listview多项目与搜索栏,搜索栏进度无法使用当前的onclicked位置[问题]

时间:2015-10-12 02:45:47

标签: android listview android-mediaplayer onitemclicklistener android-seekbar

我现在正在listview中使用媒体播放器,并且它运行良好,每一次单击,不同的音频将在其当前位置播放。但我现在面临的问题是: 每个项目我都创建了一个Seekbar来显示媒体播放的进度。搜索栏适用于第一个 onItemclick,是的,只是第一个项,一旦用户点击第二个项目,前一个(第一个单击的项目搜索栏)和当前点击的搜索栏将运行一旦用户点击第三个项目,前两个(第一个和第二个单击的项目搜索栏也将跟随也运行),当前点击的搜索栏将一起运行。 对不起我的英语,希望你们都能提供帮助。请和谢谢:) 我的代码如下: MessageAdapter.java - >

 public void playSong(final int position,final TextView msgText, final SeekBar finaltime, final TextView voiceduration,
                     final SeekBar showprogress, final ImageView playbutton){

    /*  File filepath = new File(Environment.isExternalStorageEmulated() +  "/"+ AUDIO_RECORDER_FOLDER + "/1444021246887.amr");*/
    final Message infoposition = mMessage.get(position);
    final int infodeid = infoposition.getId();
    Log.d("adaptersong1","adaptersongtry" + infodeid);
    db = new DBHelper(getContext());
    db.getVoicePath(infodeid);
    String databasevoicepath = db.getVoicePath(infodeid);
    Log.d("adaptersong2", "adaptersongtry" + databasevoicepath);

    File filePath = new File(databasevoicepath);
    audio.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            audio.reset();

            changeicon(playbutton);
            setMsgText(msgText);


        }
    });
    Log.d("adaptersong3", "adaptersongtry" + filePath);


    try {
        audio.setDataSource(String.valueOf(filePath));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        audio.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }

    audio.start();
    finalTime = audio.getDuration();
    Log.d("getduration","simentimecheck" + finalTime);
    startTime = audio.getCurrentPosition();
    Log.d("getPosition", "simentimecheck" + startTime);
    if (oneTimeOnly == 0) {
        setFinalTime(finaltime);
       /* voiceseekbar.setMax((int) finalTime);*/
        oneTimeOnly = 1;
    }


    seekbarprogress(showprogress);


    setDuration(voiceduration);

}

private void changeicon(ImageView playbutton){
    playbutton.setImageResource(R.drawable.play);
}

private void seekbarprogress(SeekBar showprogress) {


    showprogress.setProgress((int)startTime);
    myHandler.postDelayed(createRunnable(showprogress), 100);
}


private Runnable createRunnable(final SeekBar createSeekbarAgain)

{
     Runnable UpdateSongTime = new Runnable() {
        public void run() {
            startTime = audio.getCurrentPosition();
            seekbaragain(createSeekbarAgain);
            myHandler.postDelayed(this, 100);
        }
    };
    return UpdateSongTime;
}

private void seekbaragain(SeekBar createSeekbarAgain){
    createSeekbarAgain.setProgress((int) startTime);
}

private void setDuration(TextView voiceduration){
    if( TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
            TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime)) < 10){
        voiceduration.setText(String.format("00:0%d ",
                        TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
                                TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime)))
        );
    }else{
        voiceduration.setText(String.format("00:%d ",
                TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
                        TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime))));
    }


}
private void setFinalTime(SeekBar finaltime){
    finaltime.setMax((int) finalTime);
}

请帮助:)如果您需要查看更多代码以获取更多信息,请发表评论,我愿意这样做。

0 个答案:

没有答案