Skip to content

Commit

Permalink
Merge pull request #8 from brianwernick/event_bus_abstraction
Browse files Browse the repository at this point in the history
Event bus abstraction
  • Loading branch information
brianwernick committed Aug 7, 2015
2 parents f8279bc + c6e5bb2 commit fe1bd78
Show file tree
Hide file tree
Showing 31 changed files with 232 additions and 382 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ ExoMedia
============
A Utility class that wraps the ExoPlayer in to a standardized
View and API much like the built in Android VideoView and MediaPlayer.
Additionally, to simplify playback of media lists a playlist manager
and playlist service have been provided.

Since the ExoPlayer is only supported on JellyBean or greater devices that
pass the Android Compatibility Test Suite (CTS), the EMVideoView will gracefully
Expand All @@ -26,7 +28,7 @@ The latest AAR (Android Archive) files can be downloaded from JCenter [ExoMedia]
Or included in your gradle dependencies

```groovy
compile 'com.devbrackets.android:exomedia:2.2.4'
compile 'com.devbrackets.android:exomedia:2.3.0'
```

Additionally, if you use ProGuard you will need to add the following rule
Expand Down Expand Up @@ -103,4 +105,4 @@ under [Attribution 4.0 International][2]
[2]: http://creativecommons.org/licenses/by/4.0/
[3]: https://bintray.com/brianwernick/maven/ExoMedia/view#files
[4]: http://devbrackets.com/dev/libs/exomedia.html
[5]: http://devbrackets.com/dev/libs/docs/exomedia/2.2.4/index.html
[5]: http://devbrackets.com/dev/libs/docs/exomedia/2.3.0/index.html
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter();
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.novoda:bintray-release:0.2.7'
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

dependencies {
compile project(':library')
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.devbrackets.android.exomediademo.data.MediaItem;
import com.devbrackets.android.exomediademo.helper.AudioItems;
import com.devbrackets.android.exomediademo.manager.PlaylistManager;
import com.devbrackets.android.exomediademo.service.AudioService;
import com.squareup.picasso.Picasso;

import java.util.Formatter;
Expand Down Expand Up @@ -250,9 +249,6 @@ private boolean setupPlaylistManager() {
return false;
}

//Create and setup the playlist
playlistManager.setMediaServiceClass(AudioService.class);

List<MediaItem> mediaItems = new LinkedList<>();
for (AudioItems.AudioItem item : AudioItems.getItems()) {
MediaItem mediaItem = new MediaItem(item);
Expand Down
8 changes: 2 additions & 6 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ apply plugin: 'maven'
apply plugin: 'bintray-release'

def versionMajor = 2
def versionMinor = 2
def versionPatch = 4
def versionMinor = 3
def versionPatch = 0

// Maven GAV
def libraryGroupId = 'com.devbrackets.android'
def libraryBaseName = 'exomedia'
def libraryVersion = "${versionMajor}.${versionMinor}.${versionPatch}" // release version
Expand All @@ -15,9 +14,6 @@ dependencies {
// Android
compile 'com.android.support:appcompat-v7:22.2.1' // includes support-v4

// Event Bus
compile 'com.squareup:otto:1.3.8'

// ExoPlayer
compile 'com.google.android.exoplayer:exoplayer:r1.4.2'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import com.devbrackets.android.exomedia.event.EMMediaProgressEvent;
import com.devbrackets.android.exomedia.event.EMVideoViewControlVisibilityEvent;
import com.devbrackets.android.exomedia.listener.EMVideoViewControlsCallback;
import com.devbrackets.android.exomedia.util.EMEventBus;
import com.devbrackets.android.exomedia.util.TimeFormatUtil;
import com.squareup.otto.Bus;

/**
* This is a simple abstraction for the EMVideoView to have a single "View" to add
Expand Down Expand Up @@ -86,7 +86,9 @@ public interface SeekCallbacks {
private Handler visibilityHandler = new Handler();

private EMVideoView videoView;
private Bus bus;

@Nullable
private EMEventBus bus;

private SeekCallbacks seekCallbacks;

Expand Down Expand Up @@ -116,9 +118,9 @@ public DefaultControls(Context context, AttributeSet attrs, int defStyleAttr, in
* Sets the bus to use for dispatching Events that correspond to the callbacks
* listed in {@link com.devbrackets.android.exomedia.listener.EMVideoViewControlsCallback}
*
* @param bus The Otto bus to dispatch events on
* @param bus The EventBus to dispatch events on
*/
public void setBus(Bus bus) {
public void setBus(@Nullable EMEventBus bus) {
this.bus = bus;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.Log;

import com.devbrackets.android.exomedia.builder.HlsRenderBuilder;
Expand All @@ -29,13 +30,12 @@
import com.devbrackets.android.exomedia.listener.EMProgressCallback;
import com.devbrackets.android.exomedia.listener.ExoPlayerListener;
import com.devbrackets.android.exomedia.util.EMDeviceUtil;
import com.devbrackets.android.exomedia.util.EMEventBus;
import com.devbrackets.android.exomedia.util.MediaUtil;
import com.devbrackets.android.exomedia.util.Repeater;
import com.devbrackets.android.exomedia.util.StopWatch;
import com.google.android.exoplayer.audio.AudioCapabilities;
import com.google.android.exoplayer.audio.AudioCapabilitiesReceiver;
import com.squareup.otto.Bus;
import com.squareup.otto.Produce;

/**
* An AudioPlayer that uses the ExoPlayer as the backing architecture. If the current device
Expand Down Expand Up @@ -75,7 +75,8 @@ public static AudioType get(Uri uri) {

private boolean overridePosition = false;

private Bus bus;
@Nullable
private EMEventBus bus;
private EMProgressCallback progressCallback;

private Repeater pollRepeater = new Repeater();
Expand Down Expand Up @@ -168,19 +169,19 @@ public void setProgressPollDelay(int milliSeconds) {
/**
* Sets the bus to use for dispatching Events such as the poll progress
*
* @param bus The Otto bus to dispatch events on
* @param bus The EventBus to dispatch events on
*/
public void setBus(Bus bus) {
public void setBus(@Nullable EMEventBus bus) {
this.bus = bus;
listenerMux.setBus(bus);
}

/**
* Starts the progress poll.
*
* @param bus The Otto Bus event dispatcher that the listener is connected to
* @param bus The EventBus event dispatcher that the listener is connected to
*/
public void startProgressPoll(Bus bus) {
public void startProgressPoll(@Nullable EMEventBus bus) {
setBus(bus);

if (bus != null) {
Expand All @@ -204,7 +205,7 @@ public void startProgressPoll(EMProgressCallback callback) {

/**
* Stops the progress poll
* (see {@link #startProgressPoll(Bus)})
* (see {@link #startProgressPoll(EMEventBus)})
*/
public void stopProgressPoll() {
pollRepeater.stop();
Expand Down Expand Up @@ -237,11 +238,6 @@ public String getUserAgent() {
return String.format(USER_AGENT_FORMAT, BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")", Build.VERSION.RELEASE, Build.MODEL);
}

@Produce
public EMMediaProgressEvent produceMediaProgressEvent() {
return currentMediaProgressEvent;
}

/**
* ***************************************
* Start of the standard MediaPlayer APIs *
Expand Down Expand Up @@ -410,7 +406,7 @@ public void start() {

/**
* If an audio item is currently in playback, it will be paused and the progressPoll
* will be stopped (see {@link #startProgressPoll(com.squareup.otto.Bus)})
* will be stopped (see {@link #startProgressPoll(EMEventBus)})
*/
public void pause() {
if (!useExo) {
Expand All @@ -424,7 +420,7 @@ public void pause() {

/**
* If an audio item is currently in playback then the playback will be stopped
* and the progressPoll will be stopped (see {@link #startProgressPoll(com.squareup.otto.Bus)})
* and the progressPoll will be stopped (see {@link #startProgressPoll(EMEventBus)})
*/
public void stopPlayback() {
if (!useExo) {
Expand Down Expand Up @@ -582,7 +578,7 @@ public void removeExoPlayerListener(ExoPlayerListener listener) {

/**
* Sets the listener to inform of VideoPlayer prepared events. This can also be
* accessed through the Otto event {@link com.devbrackets.android.exomedia.event.EMMediaPreparedEvent}
* accessed through the bus event {@link com.devbrackets.android.exomedia.event.EMMediaPreparedEvent}
*
* @param listener The listener
*/
Expand All @@ -592,7 +588,7 @@ public void setOnPreparedListener(MediaPlayer.OnPreparedListener listener) {

/**
* Sets the listener to inform of VideoPlayer completion events. This can also be
* accessed through the Otto event {@link com.devbrackets.android.exomedia.event.EMMediaCompletionEvent}
* accessed through the bus event {@link com.devbrackets.android.exomedia.event.EMMediaCompletionEvent}
*
* @param listener The listener
*/
Expand All @@ -602,7 +598,7 @@ public void setOnCompletionListener(MediaPlayer.OnCompletionListener listener) {

/**
* Sets the listener to inform of playback errors. This can also be
* accessed through the Otto event {@link com.devbrackets.android.exomedia.event.EMMediaErrorEvent}
* accessed through the bus event {@link com.devbrackets.android.exomedia.event.EMMediaErrorEvent}
*
* @param listener The listener
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import android.media.MediaPlayer;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.devbrackets.android.exomedia.event.EMMediaCompletionEvent;
import com.devbrackets.android.exomedia.event.EMMediaErrorEvent;
import com.devbrackets.android.exomedia.event.EMMediaPreparedEvent;
import com.devbrackets.android.exomedia.listener.ExoPlayerListener;
import com.devbrackets.android.exomedia.util.EMEventBus;
import com.google.android.exoplayer.ExoPlayer;
import com.squareup.otto.Bus;

import java.util.LinkedList;
import java.util.List;
Expand All @@ -45,7 +46,9 @@ class EMListenerMux implements ExoPlayerListener, MediaPlayer.OnPreparedListener

private Handler delayedHandler = new Handler();
private EMListenerMuxNotifier muxNotifier;
private Bus bus;

@Nullable
private EMEventBus bus;

private List<ExoPlayerListener> exoPlayerListeners = new LinkedList<>();

Expand Down Expand Up @@ -155,7 +158,7 @@ public void onVideoSizeChanged(int width, int height, float pixelWidthHeightRati
}
}

public void setBus(Bus bus) {
public void setBus(@Nullable EMEventBus bus) {
this.bus = bus;
}

Expand Down Expand Up @@ -183,7 +186,7 @@ public void removeExoPlayerListener(ExoPlayerListener listener) {

/**
* Sets the listener to inform of VideoPlayer prepared events. This can also be
* accessed through the Otto event {@link com.devbrackets.android.exomedia.event.EMMediaPreparedEvent}
* accessed through the bus event {@link com.devbrackets.android.exomedia.event.EMMediaPreparedEvent}
*
* @param listener The listener
*/
Expand All @@ -193,7 +196,7 @@ public void setOnPreparedListener(MediaPlayer.OnPreparedListener listener) {

/**
* Sets the listener to inform of VideoPlayer completion events. This can also be
* accessed through the Otto event {@link com.devbrackets.android.exomedia.event.EMMediaCompletionEvent}
* accessed through the bus event {@link com.devbrackets.android.exomedia.event.EMMediaCompletionEvent}
*
* @param listener The listener
*/
Expand All @@ -203,7 +206,7 @@ public void setOnCompletionListener(MediaPlayer.OnCompletionListener listener) {

/**
* Sets the listener to inform of playback errors. This can also be
* accessed through the Otto event {@link com.devbrackets.android.exomedia.event.EMMediaErrorEvent}
* accessed through the bus event {@link com.devbrackets.android.exomedia.event.EMMediaErrorEvent}
*
* @param listener The listener
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ public Notification getNotification(@Nullable PendingIntent pendingIntent) {

//Set the notification category on lollipop
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_SERVICE);
builder.setCategory(Notification.CATEGORY_STATUS);
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
}

//Build the notification and set the expanded content view if there is a service to inform of clicks
Expand Down Expand Up @@ -216,9 +217,7 @@ private void updateMediaState(RemoteViews bigContent) {
return;
}

bigContent.setImageViewResource(R.id.exomedia_notification_playpause, state.isPlaying() ? R.drawable.exomedia_notification_pause
: R.drawable.exomedia_notification_play);

bigContent.setImageViewResource(R.id.exomedia_notification_playpause, state.isPlaying() ? R.drawable.exomedia_notification_pause : R.drawable.exomedia_notification_play);
bigContent.setInt(R.id.exomedia_notification_prev, "setVisibility", state.isPreviousEnabled() ? View.VISIBLE : View.INVISIBLE);
bigContent.setInt(R.id.exomedia_notification_next, "setVisibility", state.isNextEnabled() ? View.VISIBLE : View.INVISIBLE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class EMRemoteActions {
public static final String ACTION_PREVIOUS = "remote_action_previous";
public static final String ACTION_NEXT = "remote_action_next";
public static final String ACTION_STOP = "remote_action_stop";
public static final String ACTION_REPEAT = "remote_action_repeat";
public static final String ACTION_SHUFFLE = "remote_action_shuffle";

public static final String ACTION_SEEK_STARTED = "remote_action_seek_started";
public static final String ACTION_SEEK_ENDED = "remote_action_seek_ended";
Expand Down
Loading

0 comments on commit fe1bd78

Please sign in to comment.