注册

预览帧画面库:PreviewSeekBar

PreviewSeekBar

其实大家用PC优酷看视频的时候,鼠标放到进度条撒花姑娘就可以预览到所指向的帧画面。

一个叫[Ruben Sousa](https://medium.com/@rubensousa)的哥们做出了一个库并开源。

效果如下L:

7e3de8f46b48e5e8de45fd986d2dc375.gif

使用说明:

Build

  1. dependencies {
  2.     compile 'com.github.rubensousa:previewseekbar:0.3'
  3. }

Add the following XML:

  1. <com.github.rubensousa.previewseekbar.PreviewSeekBarLayout
  2.       android:id="@+id/previewSeekBarLayout"
  3.       android:layout_width="match_parent"
  4.       android:layout_height="wrap_content"
  5.       android:orientation="vertical">
  6.       <FrameLayout
  7.           android:id="@+id/previewFrameLayout"
  8.           android:layout_width="@dimen/video_preview_width"
  9.           android:layout_height="@dimen/video_preview_height">
  10.           <View
  11.               android:id="@+id/videoView"
  12.               android:layout_width="match_parent"
  13.               android:layout_height="match_parent"
  14.               android:layout_gravity="start"
  15.               android:background="@color/colorPrimary" />
  16.       </FrameLayout>
  17.       <com.github.rubensousa.previewseekbar.PreviewSeekBar
  18.           android:id="@+id/previewSeekBar"
  19.           android:layout_width="match_parent"
  20.           android:layout_height="wrap_content"
  21.           android:layout_below="@id/previewFrameLayout"
  22.           android:layout_marginTop="25dp"
  23.           android:max="800" />
  24. </com.github.rubensousa.previewseekbar.PreviewSeekBarLayout>

你需要在PreviewSeekBarLayout中至少添加一个PreviewSeekBar和一个FrameLayout,否则会出现异常。

PreviewSeekBarLayout继承自RelativeLayout因此还可以添加别的视图或者布局。

为seekBar添加一个标准的OnSeekBarChangeListener:

  1. // setOnSeekBarChangeListener was overridden to do the same as below
  2. seekBar.addOnSeekBarChangeListener(this);

实现你自己的预览逻辑:

  1. @Override
  2. public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
  3.     // I can't help anymore
  4. }

Github地址:https://github.com/rubensousa/PreviewSeekBar

下载地址:Store-feature-rx2.zip

0 个评论

要回复文章请先登录注册