SeekBar secondaryProgress未显示

时间:2017-06-20 06:26:38

标签: android progress seekbar

我有一个问题,我有一个搜索栏,我想使用seekBar的辅助进度条显示ExoPlayer媒体文件的缓冲进度,问题是它没有显示。我在API 21上运行 这是xml代码:

<SeekBar
                android:id="@+id/seekBarAudioA"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:maxHeight="3dip"
                android:minHeight="3dip"
                android:progressDrawable="@drawable/seek_bar_progress"
                android:secondaryProgressTint="@android:color/holo_blue_dark"
                android:thumbTint="@color/amber"
                app:layout_constraintBottom_toBottomOf="@+id/play_pause"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toRightOf="@+id/play_pause"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="@+id/play_pause" />

这是java代码:

 SeekBar = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                while (currentlyPlaying && currentAudioHolder.getAdapterPosition() == audioPosition) {
                    int duration = (int) exoPlayer.getDuration();
                    currentAudioHolder.seekBarAudio.setMax(duration);
                    currentAudioHolder.seekBarAudio.setSecondaryProgress((int) exoPlayer.getBufferedPosition());
                    final int currPosition = (int) exoPlayer.getCurrentPosition();
                    Log.d("Buffer", "secondary progress bar position is: " + (int) exoPlayer.getBufferedPosition() + ", and the current position is: " + currPosition);
                    currentAudioHolder.seekBarAudio.setProgress(currPosition);
                    ((ChatActivity) context).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            currentAudioHolder.audioLength.setText(convertTime(currPosition));
                        }
                    });
                    Thread.sleep(sleep);
                }
            } catch (InterruptedException i) {
                currentlyPlaying = false;
            }
        }
    });
    SeekBar.start();

请帮助:(

1 个答案:

答案 0 :(得分:0)

我可能会迟到,但这是我的回答:您应该检查seek_bar_progress用于android:progressDrawable的{​​{1}}文件,看看它是否如下所示:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:id="@android:id/background">
    <shape android:shape="rectangle">
        <corners android:radius="2dp"/>
        <solid android:color="@color/myBgColor"/>
    </shape>
</item>
<item android:id="@android:id/secondaryProgress">
    <scale android:scaleWidth="100%">
        <shape android:shape="rectangle">
            <corners android:radius="2dp"/>
            <solid android:color="@color/myColor"/>
        </shape>
    </scale>
</item> <item android:id="@android:id/progress">
    <clip>
        <shape android:shape="rectangle">
            <corners android:radius="2dp"/>
            <solid android:color="@color/myColor"/>
        </shape>
    </clip>
</item>

</layer-list>

我发现我的drawable中缺少@android:id/secondaryProgress id的部分,这就是为什么它不能为我工作的原因。

希望它有所帮助。