预览帧画面库:PreviewSeekBar
PreviewSeekBar
其实大家用PC优酷看视频的时候,鼠标放到进度条撒花姑娘就可以预览到所指向的帧画面。
一个叫[Ruben Sousa](https://medium.com/@rubensousa)的哥们做出了一个库并开源。
效果如下L:
使用说明:
Build
- dependencies {
- compile 'com.github.rubensousa:previewseekbar:0.3'
- }
Add the following XML:
- <com.github.rubensousa.previewseekbar.PreviewSeekBarLayout
- android:id="@+id/previewSeekBarLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <FrameLayout
- android:id="@+id/previewFrameLayout"
- android:layout_width="@dimen/video_preview_width"
- android:layout_height="@dimen/video_preview_height">
- <View
- android:id="@+id/videoView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="start"
- android:background="@color/colorPrimary" />
- </FrameLayout>
- <com.github.rubensousa.previewseekbar.PreviewSeekBar
- android:id="@+id/previewSeekBar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/previewFrameLayout"
- android:layout_marginTop="25dp"
- android:max="800" />
- </com.github.rubensousa.previewseekbar.PreviewSeekBarLayout>
你需要在PreviewSeekBarLayout中至少添加一个PreviewSeekBar和一个FrameLayout,否则会出现异常。
PreviewSeekBarLayout继承自RelativeLayout因此还可以添加别的视图或者布局。
为seekBar添加一个标准的OnSeekBarChangeListener:
- // setOnSeekBarChangeListener was overridden to do the same as below
- seekBar.addOnSeekBarChangeListener(this);
实现你自己的预览逻辑:
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- // I can't help anymore
- }