Skip to content

Commit

Permalink
Merge pull request #47 from dev-labs-bg/feature/media_controller_list…
Browse files Browse the repository at this point in the history
…ener

Feature - Media controller listener
  • Loading branch information
slavipetrov authored Aug 14, 2019
2 parents 689b799 + 17e10f9 commit 91408ff
Show file tree
Hide file tree
Showing 13 changed files with 557 additions and 241 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ buildscript {
classpath "com.android.tools.build:gradle:$versions.gradlePlugin"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$versions.bintrayPlugin"
classpath "com.github.dcendents:android-maven-gradle-plugin:$versions.mavenPlugin"
}
}

Expand Down
10 changes: 5 additions & 5 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

ext.versions = [
minSdk : 19,
compileSdk : 28,
compileSdk : 29,
buildTools : '28.0.3',
publishVersion : '0.0.8',
publishVersion : '1.1.3',
publishVersionCode: 1,
gradlePlugin : '3.4.1',
bintrayPlugin : '1.7.3',
gradlePlugin : '3.4.2',
bintrayPlugin : '1.8.4',
mavenPlugin : '1.4.1',

supportLib : '28.0.0',
constraintLayout : '1.1.3',
espresso : '3.0.1',
kotlin : '1.3.31',
kotlin : '1.3.41',
leakCanary : '1.6.1'
]
24 changes: 11 additions & 13 deletions library/release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* limitations under the License.
*/

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
apply from: 'keystore.gradle'

ext {
publishedGroupId = 'bg.devlabs.fullscreenvideoview'
artifactId = 'library'
libraryVersion = '1.1.2'
libraryVersion = '1.1.3'
}

version = libraryVersion
Expand All @@ -42,16 +41,13 @@ bintray {
}
}

install {
repositories.mavenInstaller {
pom.project {
packaging 'aar'
groupId publishedGroupId
artifactId artifactId
version libraryVersion
name artifactId
}
}
project.ext {
mavDevelopers = ["SP":"Slavi Petrov"]
mavSiteUrl = "https://github.com/dev-labs-bg/fullscreen-video-view"
mavGitUrl = mavSiteUrl + '.git'
mavProjectName = 'FullscreenVideoView'
mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
mavLibraryDescription = "FullscreenVideoView is a custom VideoView Android library which makes loading, setting up and going fullscreen for video views easy."
}

if (project.hasProperty("android")) {
Expand Down Expand Up @@ -87,4 +83,6 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
artifacts {
archives javadocJar
archives sourcesJar
}
}

apply from: 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/master/gradle-mavenizer.gradle'
11 changes: 11 additions & 0 deletions library/src/main/java/bg/devlabs/fullscreenvideoview/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.File;

import bg.devlabs.fullscreenvideoview.listener.mediacontroller.MediaControllerListener;
import bg.devlabs.fullscreenvideoview.listener.OnErrorListener;
import bg.devlabs.fullscreenvideoview.orientation.LandscapeOrientation;
import bg.devlabs.fullscreenvideoview.orientation.OrientationManager;
Expand Down Expand Up @@ -371,4 +372,14 @@ public Builder addOnErrorListener(OnErrorListener onErrorListener) {
fullscreenVideoView.addOnErrorListener(onErrorListener);
return this;
}

/**
* Adds a listener for media controller events.
*
* @return the builder instance
*/
public Builder mediaControllerListener(MediaControllerListener mediaControllerListener) {
controller.setOnMediaControllerListener(mediaControllerListener);
return this;
}
}
141 changes: 120 additions & 21 deletions library/src/main/java/bg/devlabs/fullscreenvideoview/ButtonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import java.lang.ref.WeakReference;

import bg.devlabs.fullscreenvideoview.playbackspeed.PlaybackSpeedPopupMenuListener;
import bg.devlabs.fullscreenvideoview.orientation.OrientationManager;
import bg.devlabs.fullscreenvideoview.playbackspeed.PlaybackSpeedOptions;

import static android.view.View.INVISIBLE;

/**
* Created by Slavi Petrov on 04.06.2018
Expand All @@ -45,31 +50,49 @@ class ButtonManager {
private WeakReference<ImageButton> ffwdButton;
private WeakReference<ImageButton> rewButton;
private WeakReference<ImageButton> fullscreenButton;
private WeakReference<TextView> playbackSpeedButton;

// Other
private WeakReference<OrientationManager> orientationHelper;
private WeakReference<VideoMediaPlayer> videoMediaPlayer;

ButtonManager(Context context, ImageButton startPauseButton, ImageButton ffwdButton,
ImageButton rewButton, ImageButton fullscreenButton, TextView playbackSpeedButton) {
this.exitFullscreenDrawable = ContextCompat.getDrawable(context,
R.drawable.ic_fullscreen_exit_white_48dp);
this.enterFullscreenDrawable = ContextCompat.getDrawable(context,
R.drawable.ic_fullscreen_white_48dp);
this.playDrawable = ContextCompat.getDrawable(context,
R.drawable.ic_play_arrow_white_48dp);
this.pauseDrawable = ContextCompat.getDrawable(context,
R.drawable.ic_pause_white_48dp);
this.fastForwardDrawable = ContextCompat.getDrawable(context,
R.drawable.ic_fast_forward_white_48dp);
this.rewindDrawable = ContextCompat.getDrawable(context,
R.drawable.ic_fast_rewind_white_48dp);
private PlaybackSpeedManager playbackSpeedManager;

ButtonManager(Context context,
ImageButton startPauseButton,
ImageButton ffwdButton,
ImageButton rewButton,
ImageButton fullscreenButton,
TextView playbackSpeedButton) {

this.exitFullscreenDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_fullscreen_exit_white_48dp
);
this.enterFullscreenDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_fullscreen_white_48dp
);
this.playDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_play_arrow_white_48dp
);
this.pauseDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_pause_white_48dp
);
this.fastForwardDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_fast_forward_white_48dp
);
this.rewindDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_fast_rewind_white_48dp
);

this.startPauseButton = new WeakReference<>(startPauseButton);
this.ffwdButton = new WeakReference<>(ffwdButton);
this.rewButton = new WeakReference<>(rewButton);
this.fullscreenButton = new WeakReference<>(fullscreenButton);
this.playbackSpeedButton = new WeakReference<>(playbackSpeedButton);

playbackSpeedManager = new PlaybackSpeedManager(context, playbackSpeedButton);
}

public void setupDrawables(TypedArray typedArray) {
Expand Down Expand Up @@ -97,14 +120,19 @@ private void setupRewindButton(TypedArray a) {

private void setupFullscreenButton(TypedArray a) {
Drawable enterDrawable = a.getDrawable(
R.styleable.VideoControllerView_enter_fullscreen_drawable);
R.styleable.VideoControllerView_enter_fullscreen_drawable
);

if (enterDrawable != null) {
enterFullscreenDrawable = enterDrawable;
}

fullscreenButton.get().setImageDrawable(enterFullscreenDrawable);

Drawable exitDrawable = a.getDrawable(
R.styleable.VideoControllerView_exit_fullscreen_drawable);
R.styleable.VideoControllerView_exit_fullscreen_drawable
);

if (exitDrawable != null) {
setExitFullscreenDrawable(exitDrawable);
}
Expand Down Expand Up @@ -204,6 +232,77 @@ public void setVideoMediaPlayer(VideoMediaPlayer videoMediaPlayer) {
}

public void updatePlaybackSpeedText(String text) {
playbackSpeedButton.get().setText(text);
playbackSpeedManager.setPlaybackSpeedText(text);
}

public void setFullscreenButtonClickListener(View.OnClickListener onClickListener) {
fullscreenButton.get().requestFocus();
fullscreenButton.get().setOnClickListener(onClickListener);
}

public void setStartPauseButtonClickListener(View.OnClickListener onClickListener) {
startPauseButton.get().requestFocus();
startPauseButton.get().setOnClickListener(onClickListener);
}

public void hideFullscreenButton() {
fullscreenButton.get().setVisibility(View.GONE);
}

public void setupButtonsVisibility() {
if (startPauseButton != null && !videoMediaPlayer.get().canPause()) {
startPauseButton.get().setEnabled(false);
startPauseButton.get().setVisibility(INVISIBLE);
}

if (rewButton != null && !videoMediaPlayer.get().showSeekBackwardButton()) {
rewButton.get().setEnabled(false);
rewButton.get().setVisibility(INVISIBLE);
}

if (ffwdButton != null && !videoMediaPlayer.get().showSeekForwardButton()) {
ffwdButton.get().setEnabled(false);
ffwdButton.get().setVisibility(INVISIBLE);
}

playbackSpeedManager.hidePlaybackButton(videoMediaPlayer.get().showPlaybackSpeedButton());
}

public void requestStartPauseButtonFocus() {
if (startPauseButton != null) {
startPauseButton.get().requestFocus();
}
}

public void setButtonsEnabled(boolean isEnabled) {
if (startPauseButton != null) {
startPauseButton.get().setEnabled(isEnabled);
}

if (ffwdButton != null) {
ffwdButton.get().setEnabled(isEnabled);
}

if (rewButton != null) {
rewButton.get().setEnabled(isEnabled);
}

playbackSpeedManager.setPlaybackSpeedButtonEnabled(isEnabled);
}

public void setFfwdButtonOnClickListener(View.OnClickListener onClickListener) {
ffwdButton.get().setOnClickListener(onClickListener);
}

public void setRewButtonOnClickListener(View.OnClickListener onClickListener) {
rewButton.get().setOnClickListener(onClickListener);
}

public void setPlaybackSpeedPopupMenuListener(PlaybackSpeedPopupMenuListener listener) {
playbackSpeedManager.setPlaybackSpeedButtonOnClickListener(listener);
}

public void setPlaybackSpeedOptions(PlaybackSpeedOptions playbackSpeedOptions) {
playbackSpeedManager.setPlaybackSpeedOptions(playbackSpeedOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public FullscreenVideoView(@NonNull Context context, @Nullable AttributeSet attr
init(attrs);
}

public FullscreenVideoView(@NonNull Context context, @Nullable AttributeSet attrs,
public FullscreenVideoView(@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2017 Dev Labs
*
* 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.
*/

package bg.devlabs.fullscreenvideoview;

import android.content.Context;
import android.support.v7.widget.PopupMenu;
import android.view.View;
import android.widget.TextView;

import bg.devlabs.fullscreenvideoview.playbackspeed.PlaybackSpeedPopupMenuListener;
import bg.devlabs.fullscreenvideoview.playbackspeed.OnPlaybackSpeedSelectedListener;
import bg.devlabs.fullscreenvideoview.playbackspeed.PlaybackSpeedOptions;
import bg.devlabs.fullscreenvideoview.playbackspeed.PlaybackSpeedPopupMenu;

import static android.view.View.INVISIBLE;

/**
* Created by Slavi Petrov on 14.08.2019
* Dev Labs
* [email protected]
*/
public class PlaybackSpeedManager {

private TextView playbackSpeedButton;
private PlaybackSpeedPopupMenu popupMenu;

PlaybackSpeedManager(Context context, TextView playbackSpeedButton) {
this.playbackSpeedButton = playbackSpeedButton;
// Initialize the PopupMenu
popupMenu = new PlaybackSpeedPopupMenu(context, playbackSpeedButton);
}

void setPlaybackSpeedButtonOnClickListener(
final PlaybackSpeedPopupMenuListener playbackSpeedPopupMenuListener
) {
playbackSpeedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupMenu.setOnSpeedSelectedListener(new OnPlaybackSpeedSelectedListener() {
@Override
public void onSpeedSelected(float speed, String text) {
playbackSpeedPopupMenuListener.onSpeedSelected(speed, text);
}
});

popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu menu) {
playbackSpeedPopupMenuListener.onPopupMenuDismissed();
}
});

// Show the PopupMenu
popupMenu.show();

playbackSpeedPopupMenuListener.onPopupMenuShown();
}
});
}

public void setPlaybackSpeedButtonEnabled(boolean isEnabled) {
if (playbackSpeedButton != null) {
playbackSpeedButton.setEnabled(isEnabled);
}
}

public void hidePlaybackButton(boolean showPlaybackSpeedButton) {
if (playbackSpeedButton != null && !showPlaybackSpeedButton) {
playbackSpeedButton.setEnabled(false);
playbackSpeedButton.setVisibility(INVISIBLE);
}
}

public void setPlaybackSpeedText(String text) {
playbackSpeedButton.setText(text);
}

public void setPlaybackSpeedOptions(PlaybackSpeedOptions playbackSpeedOptions) {
popupMenu.setPlaybackSpeedOptions(playbackSpeedOptions);
}
}
Loading

0 comments on commit 91408ff

Please sign in to comment.