reviewSeekBar
适合显示某物预览的SeekBar。就像Google Play Movies中看到的那样。
Google Play Movies

PreviewSeekBar的示例

Build
dependencies {
compile 'com.github.rubensousa:previewseekbar:0.2'
}
如何使用
添加下列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
}
如何结合ExoPlayer使用
如何在SimpleExoPlayerView中添加一个自定义控件
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:controller_layout_id="@layout/exoplayer_controls"/>
exoplayer_controls中的PreviewSeekBarLayout应该类似这样:
<com.github.rubensousa.previewseekbar.PreviewSeekBarLayout
android:id="@+id/previewSeekBarLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<FrameLayout
android:id="@+id/previewFrameLayout"
android:layout_width="@dimen/video_preview_width"
android:layout_height="@dimen/video_preview_height"
android:background="@drawable/video_frame"
android:padding="@dimen/video_frame_width">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/previewPlayerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:controller_layout_id="@layout/exo_simple_player_view"
app:surface_type="texture_view"
app:use_artwork="false"
app:use_controller="false" />
</FrameLayout>
<com.github.rubensousa.previewseekbar.PreviewSeekBar
android:id="@+id/exo_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/previewFrameLayout"
android:layout_marginTop="10dp"
android:max="800" />
</com.github.rubensousa.previewseekbar.PreviewSeekBarLayout>
使用下列SimpleExoPlayerView来预览:
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/previewPlayerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:controller_layout_id="@layout/exo_simple_player_view"
app:surface_type="texture_view"
app:use_artwork="false"
app:use_controller="false" />