Code Monkey home page Code Monkey logo

previewseekbar's Introduction

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.1'
    // Media3 extension that contains a TimeBar. 
    implementation 'com.github.rubensousa:previewseekbar-media3:1.1.1.0'
    // (Deprecated) ExoPlayer Extension that contains a TimeBar.
    implementation 'com.github.rubensousa:previewseekbar-exoplayer:2.18.1.0'
}

How to use with Media3

Add a custom controller to your PlayerView

<androidx.media3.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.

previewseekbar's People

Contributors

jonathan-caryl avatar rubengees avatar rubensousa avatar yt8492 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

previewseekbar's Issues

setPreviewColorTint does not work

@rubensousa :
I'm trying to set it, but it does not find the method.

         previewTimeBar = playerView.findViewById (R.id.exo_progress);
         previewTimeBar.setPreviewColorTint (R.color.colorPrimary);

How to integrate with VTT files

I have vtt file that contains info about preview images:

`
01:43:40,000 --> 01:43:50,000
out02.jpg#xywh=292,120,146,60

01:43:50,000 --> 01:44:00,000
out07.jpg#xywh=438,120,146,60

01:44:00,000 --> 01:44:10,000
out03.jpg#xywh=584,120,146,60

01:44:10,000 --> 01:44:20,000
out03.jpg#xywh=730,120,146,60

01:44:20,000 --> 01:44:30,000
out07.jpg#xywh=876,120,146,60
`
ass you see each part of that contains info about preview image and its position.

How can I integrate this vtt file with PreviewSeekBar.
I saw your samples. It seems PreviewSeekBar takes one thumbnail URL to work with, But as you see I have a list of thumbnails in my vtt file.

How to use multiple image links?

Hi, I have for example 15 big image links with 64 thumbnails inside of each, how can I use this in my case? I see only the thumbnails from the last link I call not the rest!

PreviewTimeBar not found

PreviewTimeBar not found even added normal dependency with exoplayer extension dependency. Only PreviewSeekBar is available in library. Please solve this.

PreviewSeekBar cannot be cast to com.google.android.exoplayer2.ui.TimeBar [Exoplayer 2.4.0]

Getting the following error as from exoplayer 2.4.0. i think they have change the control from a seekbar to a timebar ? The code was working well on Exoplayer 2.3.1

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.exoplayer2.ui.SimpleExoPlayerView
com.github.rubensousa.previewseekbar.PreviewSeekBar cannot be cast to com.google.android.exoplayer2.ui.TimeBar

these might help you
https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ui/DefaultTimeBar.html
https://google.github.io/ExoPlayer/doc/reference/index.html?com/google/android/exoplayer2/ui/TimeBar.OnScrubListener.html

Any fix plz ?

need to support SurfaceView

As you know, for playing dash + widevine content, we should use SurfaceView.
I tried to integrate this library, however, It seems woking not well like this.
Here is result for changing surface type to surface_view in your exoplayer_controls.xml.
and same things happen in my application.
image

How to use with videoview

I don't want to use this with any player except for default videoview and i am not able to see the preview in the frame.

Migrate away from jcenter.

Getting the following error while uisng this library.
Could not find com.github.rubensousa:previewseekbar:3.0.0.
Required by:
project :app

Change preview size

Is it possible to change the preview frame size? What should be modified in the XML/code?

Thanks!

intergrate PreviewSeekBar without EXOPlayer

hi ,your library is pretty cool, i want to use it in my own project without EXOPlayer, I've read READ_ME and haven't figured out how to do it ,you said Create a PreviewLoader and pass it to PreviewSeekBarLayout but i don't know where i should load preview to,should i pass PreviewSeekBarLayout instance to PreviewLoaderImpl ? any help is appreciated , thanks in advance

Issue: java.lang.NoSuchMethodError

When I run app on device with API 23 everything works nicely but whenever I tried to run app on device with API 19 Its gets crashed.
in logcat showing following error;

java.lang.NoSuchMethodError: com.github.rubensousa.previewseekbar.PreviewSeekBar.getThumbTintList

Kindly provide solution to handle this issue.

Render problem xml

@rubensousa : In the xml file, from the following error:

java.lang.NoClassDefFoundError: com/github/rubensousa/previewseekbar/exoplayer/R$dimen
	at com.github.rubensousa.previewseekbar.exoplayer.PreviewTimeBar.getThumbOffset(PreviewTimeBar.java:51)
	at com.github.rubensousa.previewseekbar.exoplayer.PreviewTimeBarLayout.setupMargins(PreviewTimeBarLayout.java:87)
	at com.github.rubensousa.previewseekbar.base.PreviewGeneralLayout.onLayout_Original(PreviewGeneralLayout.java:78)
	at com.github.rubensousa.previewseekbar.base.PreviewGeneralLayout.onLayout(PreviewGeneralLayout.java)
	at android.view.View.layout(View.java:19623)
	at android.view.ViewGroup.layout(ViewGroup.java:6095)
	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
	at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1780)
	at android.widget.LinearLayout.onLayout(LinearLayout.java:1546)
	at android.view.View.layout(View.java:19623)
	at android.view.ViewGroup.layout(ViewGroup.java:6095)
	at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
	at android.view.View.layout(View.java:19623)
	at android.view.ViewGroup.layout(ViewGroup.java:6095)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
	at android.view.View.layout(View.java:19623)
	at android.view.ViewGroup.layout(ViewGroup.java:6095)
	at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
	at android.view.View.layout(View.java:19623)
	at android.view.ViewGroup.layout(ViewGroup.java:6095)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:346)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
	at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
	at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
	at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.github.rubensousa.previewseekbar.exoplayer.R$dimen
	at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:181)
	at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:56)
	at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:119)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:214)
	... 30 more

Some questions

@rubensousa :
Hi, first of all I wanted to congratulate you.

Let's start with the questions:

  1. would it be possible to use the latest version of exoplayer? 2.8.1
  2. if I wanted to change the graphics of the exoplayer, would it be possible?
    if yes, how can I do?
  3. I tried to install the module but I did not understand, I also looked at the sample folder, but it seems that something escapes me.

After creating a new project I have:

  • I opened the build.gradle file and installed the dependencies:
    implementation 'com.github.rubensousa: previewseekbar: 1.2'
    implementation 'com.github.rubensousa: previewseekbar-exoplayer: 2.6.0'

from what I understand use glide, so I must also install Glide's addiction, right?

Use with PlaybackControlView

Is it possible to use your PreviewSeekBar with Exoplayer's PlaybackControlView?

Sample code:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.exoplayer2.ui.AspectRatioFrameLayout
        android:id="@+id/aspect_ratio_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <SurfaceView
            android:id="@+id/surface_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:keepScreenOn="true" />
    </com.google.android.exoplayer2.ui.AspectRatioFrameLayout>

    <com.google.android.exoplayer2.ui.PlaybackControlView
        android:id="@+id/player_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</FrameLayout>

Maven

The project is not updated in Maven Central, it does not contain the "setup" method in PreviewSeekBarLayout

[Question] How to set color programmatically?

Dear @rubensousa, thanks for your great lib.

Im using it in my project, I can set color of preview seekbar via style like below:

<item name="played_color">@color/White</item>
<item name="scrubber_color">@color/White</item>
<item name="buffered_color">@color/DeepPink</item>
<item name="unplayed_color">@color/Blue</item>
<item name="ad_marker_color">@color/White</item>
<item name="played_ad_marker_color">@color/Gray</item>

But how can i change color programmatically, pls help.

Thanks in advance.

rtl support

I am trying to implement this seekbar in a rtl mode. Everything works fine but the thumbnail does not align with the seekbar button. The two are inverted: if the seekbar progress is left, the thumbnail is on the right, and vice versa.

Here is what I am using:
previewSeekBar.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

Any help would be appreciated, thanks!

Handle LifeCycle

i'm getting stuck when implement resume in last position, can you make enhancement in exoplayermanger in the example?

Image loading Issue

Hello Sir ,

I am not able to load correct image from sprite image url. Taking more time foe load multiple image in preview image .

Still frame doesnt show

So I tried integrating the PreviewSeekBar based on the usage in your readme but i dont see the still frame showing. How do I fix this?

CustomTimeBar error implementing setAdBreakTimesMs

This method setAdBreakTimesMs cannot be override on Exoplayer 2.5.1
there is a new method

@Override
    public void setAdGroupTimesMs(@Nullable long[] adGroupTimesMs, @Nullable boolean[] playedAdGroups, int adGroupCount) {

    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.