Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

ExoPlayer 2 - Fix build by removing notils #45

Merged
merged 3 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,10 @@ android {
dependencies {
compile 'com.google.android.exoplayer:exoplayer:r2.4.1'
compile 'com.novoda:notils-java:3.0.2'
compile ('com.novoda:notils-android:3.0.2') {
exclude group: 'com.android.support', module: 'support-v4'
}

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.7.22'
testCompile 'org.easytesting:fest-assert-core:2.0M10'

androidTestCompile 'org.mockito:mockito-core:2.7.22'
androidTestCompile 'org.easytesting:fest-assert-core:2.0M10'
androidTestCompile 'com.linkedin.dexmaker:dexmaker:2.2.0'
androidTestCompile 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'

androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}

project.afterEvaluate({
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/com/novoda/noplayer/NoPlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.SubtitleView;
import com.novoda.noplayer.exoplayer.AspectRatioChangeCalculator;
import com.novoda.notils.caster.Views;

public class NoPlayerView extends FrameLayout implements AspectRatioChangeCalculator.Listener, PlayerView {

Expand All @@ -35,11 +34,11 @@ public NoPlayerView(Context context, AttributeSet attrs, int defStyleAttr) {
protected void onFinishInflate() {
super.onFinishInflate();
View.inflate(getContext(), R.layout.noplayer_view, this);
videoFrame = Views.findById(this, R.id.video_frame);
shutterView = Views.findById(this, R.id.shutter);
surfaceView = Views.findById(this, R.id.surface_view);
videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
shutterView = findViewById(R.id.shutter);
surfaceView = (SurfaceView) findViewById(R.id.surface_view);
surfaceView.getHolder().addCallback(surfaceHolderProvider);
subtitleView = Views.findById(this, R.id.subtitles_layout);
subtitleView = (SubtitleView) findViewById(R.id.subtitles_layout);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.novoda.noplayer.PlayerAudioTrack;
import com.novoda.noplayer.mediaplayer.PlaybackStateChecker.PlaybackState;
import com.novoda.noplayer.mediaplayer.forwarder.MediaPlayerForwarder;
import com.novoda.notils.logger.simple.Log;
import com.novoda.utils.NoPlayerLog;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -93,7 +93,7 @@ private MediaPlayer createAndBindMediaPlayer(SurfaceHolder surfaceHolder, Uri vi
}

private void reportCreationError(Exception ex, Uri videoUri) {
Log.w(ex, "Unable to open content: " + videoUri);
NoPlayerLog.w(ex, "Unable to open content: " + videoUri);
currentState = PlaybackState.ERROR;
internalErrorListener.onError(mediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public void onCompletion(MediaPlayer mp) {
private final MediaPlayer.OnErrorListener internalErrorListener = new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.d("Error: " + what + "," + extra);
NoPlayerLog.d("Error: " + what + "," + extra);
currentState = PlaybackState.ERROR;
MediaPlayer.OnErrorListener onErrorForwarder = forwarder.onErrorListener();
if (onErrorForwarder == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.media.MediaPlayer;

import com.novoda.noplayer.listeners.VideoSizeChangedListeners;
import com.novoda.notils.logger.simple.Log;
import com.novoda.utils.NoPlayerLog;

class VideoSizeChangedForwarder implements MediaPlayer.OnVideoSizeChangedListener {

Expand All @@ -21,7 +21,7 @@ public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
if (bothDimensionsHaveChanged(width, height)) {
videoSizeChangedListeners.onVideoSizeChanged(width, height, 0, 1);
} else {
Log.w("Video size changed but we have swallowed the event due to only 1 dimension changing");
NoPlayerLog.w("Video size changed but we have swallowed the event due to only 1 dimension changing");
}
previousWidth = width;
previousHeight = height;
Expand Down
136 changes: 136 additions & 0 deletions core/src/main/java/com/novoda/utils/NoPlayerLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.novoda.utils;


import java.io.PrintWriter;
import java.io.StringWriter;

public abstract class NoPlayerLog {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically a quick port of what we have in notils


private static final int DEPTH = 5;
private static final int CLASS_SUFFIX = 5;

private static boolean isEnabled = true;

public static void setLoggingEnabled(boolean enabled) {
isEnabled = enabled;
}

private static String logMessage(String message, Throwable throwable) {
String detailedMessage = getDetailedLog(message);
if (throwable != null) {
detailedMessage += "\n" + getStackTraceString(throwable);
}
return detailedMessage;
}

private static String getDetailedLog(String message) {
Thread current = Thread.currentThread();
final StackTraceElement trace = current.getStackTrace()[DEPTH];
final String filename = trace.getFileName();
return "[" + current.getName() + "][" + filename.substring(0, filename.length() - CLASS_SUFFIX) + "."
+ trace.getMethodName() + ":" + trace.getLineNumber() + "] " + message;
}

private static String getStackTraceString(Throwable throwable) {

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
throwable.printStackTrace(pw);
return sw.toString().trim();
} finally {
pw.close();
}
}

public static void d(String msg) {
if (!isEnabled) {
return;
}
android.util.Log.d("No-Player", logMessage(msg, null));
}

public static void d(Throwable throwable, String msg) {
if (!isEnabled) {
return;
}
android.util.Log.d("No-Player", logMessage(msg, throwable));
}

public static void e(String msg) {
if (!isEnabled) {
return;
}
android.util.Log.e("No-Player", logMessage(msg, null));
}

public static void e(Throwable throwable, String msg) {
if (!isEnabled) {
return;
}
android.util.Log.e("No-Player", logMessage(msg, throwable));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit extract constant for the tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}

public static void i(String msg) {
if (!isEnabled) {
return;
}
android.util.Log.i("No-Player", logMessage(msg, null));
}

public static void i(Throwable throwable, String msg) {
if (!isEnabled) {
return;
}
android.util.Log.i("No-Player", logMessage(msg, throwable));
}

public static void v(String msg) {
if (!isEnabled) {
return;
}
android.util.Log.v("No-Player", logMessage(msg, null));
}

public static void v(Throwable throwable, String msg) {
if (!isEnabled) {
return;
}
android.util.Log.v("No-Player", logMessage(msg, throwable));
}

public static void w(String msg) {
if (!isEnabled) {
return;
}
android.util.Log.w("No-Player", logMessage(msg, null));
}

public static void w(Throwable throwable, String msg) {
if (!isEnabled) {
return;
}
android.util.Log.w("No-Player", logMessage(msg, throwable));
}

public static void wtf(String msg) {
if (!isEnabled) {
return;
}
android.util.Log.wtf("No-Player", logMessage(msg, null));
}

public static void wtf(Throwable throwable) {
if (!isEnabled) {
return;
}
android.util.Log.wtf("No-Player", logMessage("", throwable));
}

public static void wtf(Throwable throwable, String msg) {
if (!isEnabled) {
return;
}
android.util.Log.wtf("No-Player", logMessage(msg, throwable));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.novoda.noplayer.PlayerAudioTrack;
import com.novoda.noplayer.SurfaceHolderRequester;
import com.novoda.noplayer.mediaplayer.forwarder.MediaPlayerForwarder;
import com.novoda.utils.NoPlayerLog;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -28,7 +29,6 @@

import utils.ExceptionMatcher;

import static com.novoda.notils.logger.simple.Log.setShowLogs;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -98,7 +98,7 @@ public class AndroidMediaPlayerFacadeTest {

@Before
public void setUp() {
setShowLogs(false);
NoPlayerLog.setLoggingEnabled(false);

facade = new AndroidMediaPlayerFacade(context, forwarder, audioManager, trackSelector, playbackStateChecker, mediaPlayerCreator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.novoda.noplayer.mediaplayer.forwarder.MediaPlayerForwarder;
import com.novoda.noplayer.player.PlayerInformation;
import com.novoda.noplayer.player.PlayerType;
import com.novoda.notils.logger.simple.Log;
import com.novoda.utils.NoPlayerLog;

import java.util.Collections;
import java.util.List;
Expand All @@ -50,7 +50,12 @@
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

@RunWith(Enclosed.class)
public class AndroidMediaPlayerImplTest {
Expand Down Expand Up @@ -105,7 +110,7 @@ public static class GivenPlayer extends Base {

@Before
public void setUp() {
Log.setShowLogs(false);
NoPlayerLog.setLoggingEnabled(false);
given(listenersHolder.getPreparedListeners()).willReturn(preparedListeners);
given(listenersHolder.getBufferStateListeners()).willReturn(bufferStateListeners);
given(listenersHolder.getErrorListeners()).willReturn(errorListeners);
Expand Down Expand Up @@ -677,7 +682,7 @@ public void onLoadTimeout() {

@Before
public void setUp() {
Log.setShowLogs(false);
NoPlayerLog.setLoggingEnabled(false);
SurfaceHolderRequester surfaceHolderRequester = mock(SurfaceHolderRequester.class);
given(playerView.getSurfaceHolderRequester()).willReturn(surfaceHolderRequester);
given(playerView.getStateChangedListener()).willReturn(stateChangeListener);
Expand Down
7 changes: 3 additions & 4 deletions demo/src/main/java/com/novoda/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import com.novoda.noplayer.PlayerView;
import com.novoda.noplayer.player.PlayerFactory;
import com.novoda.noplayer.player.PrioritizedPlayerTypes;
import com.novoda.notils.caster.Views;
import com.novoda.notils.logger.simple.Log;
import com.novoda.utils.NoPlayerLog;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -33,10 +32,10 @@ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.setShowLogs(true);
NoPlayerLog.setLoggingEnabled(true);
setContentView(R.layout.activity_main);
playerView = (PlayerView) findViewById(R.id.player_view);
audioSelectionButton = Views.findById(this, R.id.button_audio_selection);
audioSelectionButton = findViewById(R.id.button_audio_selection);
}

@Override
Expand Down