• Stars
    star
    3,437
  • Rank 12,995 (Top 0.3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A SeekBar suited for showing a preview of something. As seen in Google Play Movies.

PreviewSeekBar

A SeekBar suited for showing a video preview. As seen in Google Play Movies

Google Play Movies

PreviewSeekBar's sample

Build

Add the following to your app's build.gradle:

dependencies {
    // Base implementation with a standard SeekBar
    implementation 'com.github.rubensousa:previewseekbar:3.1.0'

    // ExoPlayer extension that contains a TimeBar. 
    // Grab this one if you're going to integrate with ExoPlayer
    implementation 'com.github.rubensousa:previewseekbar-exoplayer:2.18.1.0'
}

How to use with ExoPlayer

Add a custom controller to your PlayerView

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/playerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:controller_layout_id="@layout/exoplayer_controls"/>

Here's the sample's exoplayer_controls: https://github.com/rubensousa/PreviewSeekBar/blob/master/sample/src/main/res/layout/exoplayer_controls.xml

Change your TimeBar to a PreviewTimeBar

<FrameLayout
    android:id="@+id/previewFrameLayout"
    android:layout_width="@dimen/video_preview_width"
    android:layout_height="@dimen/video_preview_height"
    android:background="@drawable/video_frame">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</FrameLayout>

<com.github.rubensousa.previewseekbar.exoplayer.PreviewTimeBar
    android:id="@+id/exo_progress"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    app:previewAnimationEnabled="true"
    app:previewFrameLayout="@id/previewFrameLayout"/>

Place the View you want to use to display the preview in the FrameLayout above. In this example it's an ImageView but you can place any View inside. PreviewTimeBar will animate and show that FrameLayout for you automatically.

The FrameLayout must have the same parent as the PreviewTimeBar if you want the default animations to work

Create a PreviewLoader and pass it to the PreviewTimeBar

Note: A PreviewLoader is an interface that you need to implement yourself. This library isn't opinionated about how you actually show a preview. Check the sample code for an example on how it can be done using thumbnail sprites.

PreviewLoader imagePreviewLoader = ImagePreviewLoader();

previewTimeBar.setPreviewLoader(imagePreviewLoader);

In this project's sample, Glide is used with a custom transformation to crop the thumbnails from a thumbnail sprite.

GlideThumbnailTransformation

@Override
public void loadPreview(long currentPosition, long max) {
    GlideApp.with(imageView)
            .load(thumbnailsUrl)
            .override(GlideThumbnailTransformation.IMAGE_WIDTH,
                    GlideThumbnailTransformation.IMAGE_HEIGHT)
            .transform(new GlideThumbnailTransformation(currentPosition))
            .into(imageView);
}

Listen for scrub events to control playback state

When the user starts scrubbing the PreviewTimeBar, you should pause the video playback After the user is done selecting the new video position, you can resume it.

previewTimeBar.addOnScrubListener(new PreviewBar.OnScrubListener() {
    @Override
    public void onScrubStart(PreviewBar previewBar) {
        player.setPlayWhenReady(false);
    }

    @Override
    public void onScrubMove(PreviewBar previewBar, int progress, boolean fromUser) {
        
    }

    @Override
    public void onScrubStop(PreviewBar previewBar) {
        player.setPlayWhenReady(true);
    }
});

Customize the PreviewTimeBar

Available XML attributes:

<attr name="previewAnimationEnabled" format="boolean" />
<attr name="previewEnabled" format="boolean" />
<attr name="previewAutoHide" format="boolean" />
// Disables auto hiding the preview. 
// Default is true, which means the preview is hidden 
// when the user stops scrubbing the PreviewSeekBar
previewTimeBar.setAutoHidePreview(false);

// Shows the preview
previewTimeBar.showPreview();

// Hides the preview
previewTimeBar.hidePreview();

// Disables revealing the preview
previewTimeBar.setPreviewEnabled(false);

// Disables the current animation
previewTimeBar.setPreviewAnimationEnabled(false);

// Change the default animation
previewTimeBar.setPreviewAnimator(new PreviewFadeAnimator());

// Changes the color of the thumb
previewTimeBar.setPreviewThumbTint(Color.RED);

// Listen for scrub touch changes
previewTimeBar.addOnScrubListener(new PreviewBar.OnScrubListener() {
    @Override
    public void onScrubStart(PreviewBar previewBar) {
        
    }

    @Override
    public void onScrubMove(PreviewBar previewBar, int progress, boolean fromUser) {
        
    }

    @Override
    public void onScrubStop(PreviewBar previewBar) {
        
    }
});

// Listen for preview visibility changes
previewTimeBar.addOnPreviewVisibilityListener(new PreviewBar.OnPreviewVisibilityListener() {
    @Override
    public void onVisibilityChanged(PreviewBar previewBar, boolean isPreviewShowing) {
        
    }
});

How to use with a standard SeekBar

Setup your layout like the following:

<FrameLayout
  android:id="@+id/previewFrameLayout"
  android:layout_width="160dp"
  android:layout_height="90dp">

  <ImageView
      android:id="@+id/imageView"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

</FrameLayout>

<com.github.rubensousa.previewseekbar.PreviewSeekBar
  android:id="@+id/previewSeekBar"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="24dp"
  android:max="800"
  app:previewFrameLayout="@id/previewFrameLayout"/>

Place the View you want to use to display the preview in the FrameLayout above. In this example it's an ImageView but you can place any View inside. PreviewSeekBar will animate and show that FrameLayout for you automatically.

The FrameLayout must have the same parent as the PreviewSeekBar if you want the default animations to work

Create a PreviewLoader and pass it to the PreviewSeekBar

PreviewSeekBar previewSeekBar = findViewById(R.id.previewSeekBar);

PreviewLoader imagePreviewLoader = ImagePreviewLoader();

previewSeekbar.setPreviewLoader(imagePreviewLoader);

Customization

Available XML attributes for styling:

<attr name="previewAnimationEnabled" format="boolean" />
<attr name="previewEnabled" format="boolean" />
<attr name="previewThumbTint" format="color" />
<attr name="previewAutoHide" format="boolean" />

Important note

This library is just an UI component for displaying previews. It doesn't handle generating thumbnail sprites from videos.

License

Copyright 2017 The Android Open Source Project
Copyright 2020 Rúben Sousa

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

GravitySnapHelper

A SnapHelper that snaps a RecyclerView to an edge.
Java
4,987
star
2

ViewPagerCards

ViewPager cards inspired by Duolingo
Java
4,065
star
3

FloatingToolbar

A toolbar that morphs from a FloatingActionButton
Java
1,551
star
4

BottomSheetBuilder

A simple library that creates BottomSheets according to the Material Design specs
Java
558
star
5

Decorator

Decorator is an Android library that helps creating composable margins and dividers in RecyclerViews
Kotlin
533
star
6

RaiflatButton

A raised button that lowers down to 0dp of elevation
Java
330
star
7

RecyclerViewNestedExample

From: https://rubensousa.com/2019/08/16/nested_recyclerview_part1/ and https://rubensousa.com/2019/08/27/saving_scroll_state_of_nested_recyclerviews/
Kotlin
165
star
8

BottomSheetExample

A sample project with the new BottomSheet classes from the android support library
Java
129
star
9

Transitions

A sample that showcases some transitions
Java
118
star
10

DpadRecyclerView

A RecyclerView built for Android TV with Compose in mind and as a replacement for Leanback's BaseGridView.
Kotlin
103
star
11

SlidingTabs

Tabs created with the new android.support.design.widget.TabLayout
Java
25
star
12

StackView

A view that arranges its children in the form of a stack
Java
16
star
13

lista

Lista helps you building composable sections and nested lists in RecyclerViews.
Kotlin
14
star
14

LoadMoreAdapter

A RecyclerView adapter that offers support to loading more items
Java
9
star
15

AndroidGithubPackage

Sample Android library that's published to GitHub Packages using a GitHub Action
Java
5
star
16

FragmentContainerViewIssue

https://issuetracker.google.com/issues/146359827
Kotlin
3
star
17

TabLayoutAdapter

A helper library to easily create tabs with TabLayout
Java
3
star
18

NavigationViewExample

An example app with NavigationView of the android.support.design library
Java
3
star
19

CropView

A simple view that selects an area for cropping
Java
3
star
20

WorkManagerKitkatBug

https://issuetracker.google.com/issues/122578012
Kotlin
2
star
21

rubensousa.github.io

SCSS
2
star
22

Android_8.0_Accessibility_Crash

Kotlin
2
star
23

WorkManagerConcurrent

https://issuetracker.google.com/issues/121345393
Kotlin
1
star
24

Mieti

Aplicação para o cálculo da média do Mestrado Integrado em Engenharia de Telecomunicações e Informática da Universidade do Minho.
Java
1
star
25

adventofcode2017

Solutions for Advent of Code
Kotlin
1
star
26

StateSaverIssue

Java
1
star