Skip to content

Commit

Permalink
Merge pull request #25 from dev-labs-bg/feature/playback-speed-contro…
Browse files Browse the repository at this point in the history
…ller

Feature/playback speed controller
  • Loading branch information
slavipetrov authored Oct 4, 2018
2 parents 1758c9e + 7ae087f commit 93d9046
Show file tree
Hide file tree
Showing 25 changed files with 473 additions and 206 deletions.
75 changes: 42 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
![logo](https://raw.githubusercontent.com/dev-labs-bg/fullscreen-video-view/master/logo.png)
==========
===
[![Download](https://api.bintray.com/packages/slavipetrov/maven/fullscreen-video-view/images/download.svg) ](https://bintray.com/slavipetrov/maven/fullscreen-video-view/_latestVersion)
[![Build Status](https://travis-ci.org/dev-labs-bg/fullscreen-video-view.svg?branch=0.0.9)](https://travis-ci.org/dev-labs-bg/fullscreen-video-view)
[![Build Status](https://travis-ci.org/dev-labs-bg/fullscreen-video-view.svg?branch=1.0.0)](https://travis-ci.org/dev-labs-bg/fullscreen-video-view)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5d2c2572dd7b4a2fb5eeabd6c2e18fbc)](https://www.codacy.com/app/slavipetrov/fullscreen-video-view?utm_source=github.com&utm_medium=referral&utm_content=dev-labs-bg/fullscreen-video-view&utm_campaign=Badge_Grade)

FullscreenVideoView is a custom VideoView Android library which makes loading, setting up and going fullscreen for video views easy.

<img src="https://github.com/dev-labs-bg/fullscreen-video-view/blob/master/preview.gif" width="250" height="445">

Download
==========
===
You can use Gradle:
```gradle
compile 'bg.devlabs.fullscreenvideoview:library:0.0.9'
compile 'bg.devlabs.fullscreenvideoview:library:1.0.0'
```
or Maven:
```maven
<dependency>
<groupId>bg.devlabs.fullscreenvideoview</groupId>
<artifactId>library</artifactId>
<version>0.0.9</version>
<version>1.0.0</version>
<type>pom</type>
</dependency>
```

How to use FullscreenVideoView?
==========
===
Declare the FullscreenVideoView in the XML layout file
```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Expand All @@ -50,28 +49,28 @@ The Activity where the FullscreenVideoView is declared should handle configurati
```

Basic video loading (from URL or from a file)
```java
```kotlin
// Loading from URL
@Override public void onCreate(Bundle savedInstanceState) {
override fun onCreate(savedInstanceState: Bundle?) {
...
FullscreenVideoView fullscreenVideoView = findViewById(R.id.fullscreenVideoView);
String videoUrl = "http://clips.vorwaerts-gmbh.de/VfE_html5.mp4";
fullscreenVideoView.videoUrl(videoUrl);
val fullscreenVideoView = findViewById(R.id.fullscreenVideoView)
val videoUrl = "https://clips.vorwaerts-gmbh.de/VfE_html5.mp4"
fullscreenVideoView.videoUrl(videoUrl)
}

// Loading from file
@Override public void onCreate(Bundle savedInstanceState) {
override fun onCreate(savedInstanceState: Bundle?) {
...
FullscreenVideoView fullscreenVideoView = findViewById(R.id.fullscreenVideoView);
File videoFile = new File("file_path");
fullscreenVideoView.videoFile(videoFile);
val fullscreenVideoView = findViewById(R.id.fullscreenVideoView)
val videoFile = new File("file_path")
fullscreenVideoView.videoFile(videoFile)
}
```

Change controls drawable resources
----------
Java
```java
---
Java or Kotlin
```kotlin
fullscreenVideoView.videoUrl(videoUrl)
.playDrawable(R.drawable.ic_play)
.pauseDrawable(R.drawable.ic_pause)
Expand All @@ -96,39 +95,49 @@ XML
```

Enable/disable controls
----------
```java
---
```kotlin
fullscreenVideoView.videoUrl(videoUrl)
.canPause(true)
.canSeekBackward(false)
.canSeekForward(false)
.disablePause()
.addSeekBackwardButton()
.addSeekForwardButton()
```

Enable video auto-start
----------
```java
---
```kotlin
fullscreenVideoView.videoUrl(videoUrl)
.enableAutoStart()
```

Customize fast-forward and/or rewind seconds
----------
```java
---
```kotlin
fullscreenVideoView.videoUrl(videoUrl)
.fastForwardSeconds(5)
.rewindSeconds(5)
```
Change the playback speed (only for API 23 and above)
---
There are 7 playback speed values which are added by default, but they can be changed with custom ones when `playbackSpeedOptions` is used.
```kotlin
val playbackOptions = PlaybackSpeedOptions().addSpeeds(0.25f, 0.5f, 0.75f, 1f)

fullscreenVideoView.videoUrl(videoUrl)
.addPlaybackSpeedButton()
.playbackSpeedOptions(playbackOptions)
```

Compatibility
==========
===
- Minimum Android SDK: API level 19
- Compile Android SDK: API level 27
- Compile Android SDK: API level 28

Known issues
==========
===
There is a memory leak in Android 7 (API levels 24 and 25), which is known and [listed](https://github.com/square/leakcanary/issues/721)
in the LeakCanary repository issues.

License
==========
Apache 2.0. See the [LICENSE](https://github.com/dev-labs-bg/fullscreen-video-view/blob/master/LICENSE.txt) file for details.
===
Apache 2.0. See the [LICENSE](https://github.com/dev-labs-bg/fullscreen-video-view/blob/master/LICENSE.txt) file for details.
12 changes: 6 additions & 6 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
ext.versions = [
minSdk : 19,
compileSdk : 27,
buildTools : '27.0.3',
compileSdk : 28,
buildTools : '28.0.3',
publishVersion : '0.0.8',
publishVersionCode: 1,
gradlePlugin : '3.1.2',
gradlePlugin : '3.2.0',
bintrayPlugin : '1.7.3',
mavenPlugin : '1.4.1',

supportLib : '27.1.1',
supportLib : '28.0.0',
espresso : '3.0.1',
kotlin : '1.2.41',
leakCanary : '1.5.4'
kotlin : '1.2.71',
leakCanary : '1.6.1'
]
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 25 17:03:14 EEST 2018
#Thu Oct 04 12:51:40 EEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ android {
targetSdkVersion versions.compileSdk
versionCode versions.publishVersionCode
versionName versions.publishVersion

}
lintOptions {
abortOnError false
Expand All @@ -22,6 +21,7 @@ android {

dependencies {
implementation "com.android.support:appcompat-v7:$versions.supportLib"
implementation "com.android.support:design:$versions.supportLib"
}

apply from: 'release.gradle'
2 changes: 1 addition & 1 deletion library/release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply from: 'keystore.gradle'
ext {
publishedGroupId = 'bg.devlabs.fullscreenvideoview'
artifactId = 'library'
libraryVersion = '0.0.9'
libraryVersion = '1.0.0'
}

version = libraryVersion
Expand Down
106 changes: 80 additions & 26 deletions library/src/main/java/bg/devlabs/fullscreenvideoview/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;

import java.io.File;
Expand All @@ -24,8 +26,10 @@ public class Builder {
private final OrientationHelper orientationHelper;
private final VideoMediaPlayer videoMediaPlayer;

Builder(FullscreenVideoView fullscreenVideoView, VideoControllerView controller,
OrientationHelper orientationHelper, VideoMediaPlayer videoMediaPlayer) {
Builder(FullscreenVideoView fullscreenVideoView,
VideoControllerView controller,
OrientationHelper orientationHelper,
VideoMediaPlayer videoMediaPlayer) {
this.fullscreenVideoView = fullscreenVideoView;
this.controller = controller;
this.orientationHelper = orientationHelper;
Expand All @@ -47,63 +51,63 @@ public Builder enableAutoStart() {
return this;
}

public Builder enterFullscreenDrawable(@NonNull Drawable enterFullscreenDrawable) {
controller.setEnterFullscreenDrawable(enterFullscreenDrawable);
public Builder enterFullscreenDrawable(@NonNull Drawable drawable) {
controller.setEnterFullscreenDrawable(drawable);
return this;
}

public Builder enterFullscreenDrawable(@DrawableRes int enterFullscreenDrawableResId) {
controller.setEnterFullscreenDrawable(getDrawable(enterFullscreenDrawableResId));
public Builder enterFullscreenDrawable(@DrawableRes int drawableResId) {
controller.setEnterFullscreenDrawable(getDrawable(drawableResId));
return this;
}

public Builder exitFullscreenDrawable(@NonNull Drawable exitFullscreenDrawable) {
controller.setExitFullscreenDrawable(exitFullscreenDrawable);
public Builder exitFullscreenDrawable(@NonNull Drawable drawable) {
controller.setExitFullscreenDrawable(drawable);
return this;
}

public Builder exitFullscreenDrawable(@DrawableRes int exitFullscreenDrawable) {
controller.setExitFullscreenDrawable(getDrawable(exitFullscreenDrawable));
public Builder exitFullscreenDrawable(@DrawableRes int drawableResId) {
controller.setExitFullscreenDrawable(getDrawable(drawableResId));
return this;
}

public Builder playDrawable(@NonNull Drawable playDrawable) {
controller.setPlayDrawable(playDrawable);
public Builder playDrawable(@NonNull Drawable drawable) {
controller.setPlayDrawable(drawable);
return this;
}

public Builder playDrawable(@DrawableRes int playDrawable) {
controller.setPlayDrawable(getDrawable(playDrawable));
public Builder playDrawable(@DrawableRes int drawableResId) {
controller.setPlayDrawable(getDrawable(drawableResId));
return this;
}

public Builder pauseDrawable(@NonNull Drawable pauseDrawable) {
controller.setPauseDrawable(pauseDrawable);
public Builder pauseDrawable(@NonNull Drawable drawable) {
controller.setPauseDrawable(drawable);
return this;
}

public Builder pauseDrawable(@DrawableRes int pauseDrawable) {
controller.setPauseDrawable(getDrawable(pauseDrawable));
public Builder pauseDrawable(@DrawableRes int drawableResId) {
controller.setPauseDrawable(getDrawable(drawableResId));
return this;
}

public Builder fastForwardDrawable(@NonNull Drawable fastForwardDrawable) {
controller.setFastForwardDrawable(fastForwardDrawable);
public Builder fastForwardDrawable(@NonNull Drawable drawable) {
controller.setFastForwardDrawable(drawable);
return this;
}

public Builder fastForwardDrawable(@DrawableRes int fastForwardDrawable) {
controller.setFastForwardDrawable(getDrawable(fastForwardDrawable));
public Builder fastForwardDrawable(@DrawableRes int drawableResId) {
controller.setFastForwardDrawable(getDrawable(drawableResId));
return this;
}

public Builder rewindDrawable(@NonNull Drawable rewindDrawable) {
controller.setRewindDrawable(rewindDrawable);
public Builder rewindDrawable(@NonNull Drawable drawable) {
controller.setRewindDrawable(drawable);
return this;
}

public Builder rewindDrawable(@DrawableRes int rewindDrawable) {
controller.setRewindDrawable(getDrawable(rewindDrawable));
public Builder rewindDrawable(@DrawableRes int drawableResId) {
controller.setRewindDrawable(getDrawable(drawableResId));
return this;
}

Expand Down Expand Up @@ -132,16 +136,61 @@ public Builder portraitOrientation(PortraitOrientation portraitOrientation) {
return this;
}

public Builder disablePause() {
videoMediaPlayer.disablePause();
return this;
}

public Builder addSeekForwardButton() {
videoMediaPlayer.addSeekForwardButton();
return this;
}

public Builder addSeekBackwardButton() {
videoMediaPlayer.addSeekBackwardButton();
return this;
}

@RequiresApi(Build.VERSION_CODES.M)
public Builder addPlaybackSpeedButton() {
videoMediaPlayer.addPlaybackSpeedButton();
return this;
}

/**
* Method implementation: pass 'true' to enable and pass 'false' to disable the play/pause
* button. It's enabled by default and to disable it the user passes 'false' to the method
* or just does not use it. In this case passing 'true' or 'false' is confusing.
*
* @deprecated As of release 1.0.0, replaced by {@link #disablePause()}
*/
@Deprecated
public Builder canPause(boolean canPause) {
videoMediaPlayer.setPauseEnabled(canPause);
return this;
}

/**
* Method implementation: pass 'true' to enable and pass 'false' to disable the
* seek backward button. It's is disabled by default and to enable it the user passes 'true'
* to the method or just does not use it. In this case passing 'true' or 'false' is confusing.
*
* @deprecated As of release 1.0.0, replaced by {@link #addSeekBackwardButton()}
*/
@Deprecated
public Builder canSeekBackward(boolean canSeekBackward) {
videoMediaPlayer.setCanSeekBackward(canSeekBackward);
return this;
}

/**
* Method implementation: pass 'true' to enable and pass 'false' to disable the
* seek forward button. It's is disabled by default and to enable it the user passes 'true'
* to the method or just does not use it. In this case passing 'true' or 'false' is confusing.
*
* @deprecated As of release 1.0.0, replaced by {@link #addSeekForwardButton()}
*/
@Deprecated
public Builder canSeekForward(boolean canSeekForward) {
videoMediaPlayer.setCanSeekForward(canSeekForward);
return this;
Expand All @@ -151,4 +200,9 @@ private Drawable getDrawable(int drawableResId) {
Context context = fullscreenVideoView.getContext();
return ContextCompat.getDrawable(context, drawableResId);
}

public Builder playbackSpeedOptions(PlaybackSpeedOptions playbackSpeedOptions) {
controller.setPlaybackSpeedOptions(playbackSpeedOptions);
return this;
}
}
Loading

0 comments on commit 93d9046

Please sign in to comment.