Skip to content

Commit

Permalink
Commiting latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Pavlotsky committed Nov 14, 2016
1 parent 49c97ac commit 7dc097f
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 839 deletions.
4 changes: 2 additions & 2 deletions BasicExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
}

dependencies {
compile 'com.google.ads.interactivemedia.v3:interactivemedia:3.2.1'
compile 'com.google.ads.interactivemedia.v3:interactivemedia:3.5.2'
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-ads:9.8.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@

/**
* A VideoView that intercepts various methods and reports them back via a
* PlayerCallback.
* OnVideoCompletedListener.
*/
public class SampleVideoPlayer extends VideoView implements VideoPlayer {
public class SampleVideoPlayer extends VideoView {

private enum PlaybackState {
STOPPED, PAUSED, PLAYING
/**
* Interface for alerting caller of video completion.
*/
public interface OnVideoCompletedListener {

/**
* Called when the current video has completed playback to the end of the video.
*/
void onVideoCompleted();
}

private MediaController mMediaController;
private PlaybackState mPlaybackState;
private final List<PlayerCallback> mVideoPlayerCallbacks = new ArrayList<PlayerCallback>(1);
private final List<OnVideoCompletedListener> mOnVideoCompletedListeners = new ArrayList<>(1);

public SampleVideoPlayer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Expand All @@ -43,11 +48,10 @@ public SampleVideoPlayer(Context context) {
}

private void init() {
mPlaybackState = PlaybackState.STOPPED;
mMediaController = new MediaController(getContext());
mMediaController.setAnchorView(this);
MediaController mediaController = new MediaController(getContext());
mediaController.setAnchorView(this);

// Set OnCompletionListener to notify our callbacks when the video is completed.
// Set OnCompletionListener to notify our listeners when the video is completed.
super.setOnCompletionListener(new OnCompletionListener() {

@Override
Expand All @@ -57,23 +61,18 @@ public void onCompletion(MediaPlayer mediaPlayer) {
// player crashing when switching between videos.
mediaPlayer.reset();
mediaPlayer.setDisplay(getHolder());
mPlaybackState = PlaybackState.STOPPED;

for (PlayerCallback callback : mVideoPlayerCallbacks) {
callback.onCompleted();
for (OnVideoCompletedListener listener : mOnVideoCompletedListeners) {
listener.onVideoCompleted();
}
}
});

// Set OnErrorListener to notify our callbacks if the video errors.
// Set OnErrorListener to notify our listeners if the video errors.
super.setOnErrorListener(new OnErrorListener() {

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mPlaybackState = PlaybackState.STOPPED;
for (PlayerCallback callback : mVideoPlayerCallbacks) {
callback.onError();
}

// Returning true signals to MediaPlayer that we handled the error. This will
// prevent the completion handler from being called.
Expand All @@ -88,57 +87,11 @@ public void setOnCompletionListener(OnCompletionListener listener) {
throw new UnsupportedOperationException();
}

@Override
public void setOnErrorListener(OnErrorListener listener) {
// The OnErrorListener can only be implemented by SampleVideoPlayer.
throw new UnsupportedOperationException();
}

// Methods implementing the VideoPlayer interface.

@Override
public void play() {
start();
}

@Override
public void start() {
super.start();
// Fire callbacks before switching playback state.
switch (mPlaybackState) {
case STOPPED:
for (PlayerCallback callback : mVideoPlayerCallbacks) {
callback.onPlay();
}
break;
case PAUSED:
for (PlayerCallback callback : mVideoPlayerCallbacks) {
callback.onResume();
}
break;
default:
// Already playing; do nothing.
}
mPlaybackState = PlaybackState.PLAYING;
}

@Override
public void stopPlayback() {
super.stopPlayback();
mPlaybackState = PlaybackState.STOPPED;
}

@Override
public void pause() {
super.pause();
mPlaybackState = PlaybackState.PAUSED;
for (PlayerCallback callback : mVideoPlayerCallbacks) {
callback.onPause();
}
}

@Override
public void addPlayerCallback(PlayerCallback callback) {
mVideoPlayerCallbacks.add(callback);
public void addVideoCompletedListener(OnVideoCompletedListener listener) {
mOnVideoCompletedListeners.add(listener);
}
}

This file was deleted.

Loading

0 comments on commit 7dc097f

Please sign in to comment.