我需要一些组件或github链接来显示视频的搜索栏(或进度栏),并在设置的时间显示视频的缩略图(由搜索栏设置)
(如youtube)

非常感谢!

最佳答案

好的,我弄清楚了自己,然后上传到:

https://github.com/CorradiSebastian/SeekBarPreview

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.sebastiancorradi.seekbar.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Coded By Sebastian Corradi [email protected]"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:textColor="#AAAAAA"
        android:textSize="10dp"
        app:layout_constraintTop_toTopOf="parent" />

    <com.sebastiancorradi.seekbar.components.SeekBarPreview
        android:id="@+id/seekBarPreviewSDCard"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"/>


</android.support.constraint.ConstraintLayout>

.JAVA:
public class SeekBarPreview  extends LinearLayout {
    private SeekBar mSeekBar;
    private ImageView mPreview;
    private View rootView;

    private int totalDuration;
    private int currentPosition;
    private MediaMetadataRetriever retriever;

    public SeekBarPreview(Context context) {
        super(context);
        init();
    }

    public SeekBarPreview(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        init();
    }

    public SeekBarPreview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init(){
        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = inflater.inflate(R.layout.seekbarpreview_layout, this, true);

        mPreview = rootView.findViewById(R.id.imageView);
        mSeekBar = rootView.findViewById(R.id.seekBar);
        retriever = new MediaMetadataRetriever();

        mPreview.setScaleType(ImageView.ScaleType.CENTER_CROP);
    }

    public void setUrl(String url){
        retriever.setDataSource(url, new HashMap<String, String>());
        String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
        if (duration != null) {
            totalDuration = Integer.valueOf(duration);//milisecs
        } else {
            totalDuration = 0;
            //or throw an exception
        }
    }
    public void setUri(Uri uri){
        retriever.setDataSource(getContext(),uri);
        String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
        if (duration != null) {
            totalDuration = Integer.valueOf(duration);//milisecs
        } else {
            totalDuration = 0;
            //or throw an exception
        }
    }

    public void update(int i) {
        Long newPosition = totalDuration * i * 10L;
        Bitmap bitmap = retriever.getFrameAtTime(newPosition);
        mPreview.setImageBitmap(bitmap);


        int x = mSeekBar.getThumb().getBounds().centerX();
        int newPos = x - (i * mPreview.getWidth() / 100);
        mPreview.setX(newPos);


    }

    public void initialize(){

        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                update(i);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        mSeekBar.setProgress(1);
    }
}

在父级中,您只需添加MXL:
<com.sebastiancorradi.seekbar.components.SeekBarPreview
    android:id="@+id/seekBarPreviewSDCard"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"/>

JAVA:
SeekBarPreview seekBarPreviewSDCard = findViewById(R.id.seekBarPreviewSDCard);

        String path = "android.resource://" + getPackageName() + "/" + R.raw.bunny;
        seekBarPreviewSDCard.setUri(Uri.parse(path));

        seekBarPreviewSDCard.initialize();

关于android - 具有预览功能的seekbar,例如youtube,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48236910/

10-09 13:06