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

Commit

Permalink
Merge pull request #189 from novoda/develop
Browse files Browse the repository at this point in the history
Release 4.5.0
  • Loading branch information
pablisco authored Dec 13, 2018
2 parents 3110487 + 480c949 commit 5fbb008
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 94 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ dependencies {
implementation 'com.novoda:no-player:<latest-version>'
}
```

From no-player 4.5.0 this is also needed in the android section of your `build.gradle`

```groovy
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
}
```

### Simple usage

1. Create a `Player`:
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
allprojects {
version = '4.4.6'
version = '4.5.0'
}

def teamPropsFile(propsFile) {
Expand All @@ -9,8 +9,8 @@ def teamPropsFile(propsFile) {

buildscript {
repositories {
jcenter()
google()
jcenter()
}

dependencies {
Expand All @@ -23,8 +23,8 @@ buildscript {

subprojects {
repositories {
jcenter()
google()
jcenter()
}

apply from: teamPropsFile('static-analysis.gradle')
Expand Down
8 changes: 6 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ android {
abortOnError true
warningsAsErrors true
}

compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation 'com.google.android.exoplayer:exoplayer:2.8.4'
implementation 'com.google.android.exoplayer:exoplayer:2.9.2'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.22.0'
testImplementation 'org.mockito:mockito-core:2.23.4'
testImplementation 'org.easytesting:fest-assert-core:2.0M10'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public enum DetailErrorType {
AUDIO_UNHANDLED_FORMAT_ERROR,
AUDIO_DECODER_ERROR,
INITIALISATION_ERROR,
DECODING_METADATA_ERROR,
DECODING_SUBTITLE_ERROR,
MEDIA_PLAYER_INFO_AUDIO_NOT_PLAYING,
MEDIA_PLAYER_BAD_INTERLEAVING,
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/novoda/noplayer/PlayerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public PlayerBuilder withDowngradedSecureDecoder() {
* @see NoPlayer
*/
public NoPlayer build(Context context) throws UnableToCreatePlayerException {
Context applicationContext = context.getApplicationContext();
Handler handler = new Handler(Looper.getMainLooper());
ProvisionExecutorCreator provisionExecutorCreator = new ProvisionExecutorCreator();
DrmSessionCreatorFactory drmSessionCreatorFactory = new DrmSessionCreatorFactory(
Expand All @@ -119,7 +120,7 @@ public NoPlayer build(Context context) throws UnableToCreatePlayerException {
handler
);
NoPlayerCreator noPlayerCreator = new NoPlayerCreator(
context,
applicationContext,
prioritizedPlayerTypes,
NoPlayerExoPlayerCreator.newInstance(handler),
NoPlayerMediaPlayerCreator.newInstance(handler),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.text.TextUtils;

import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.text.SimpleSubtitleDecoder;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.google.android.exoplayer2.text.webvtt.WebvttCssStyle;
Expand Down Expand Up @@ -67,8 +68,13 @@ protected WebvttSubtitle decode(byte[] bytes, int length, boolean reset)
definedStyles.clear();

// Validate the first line of the header, and skip the remainder.
WebvttParserUtil.validateWebvttHeaderLine(parsableWebvttData);
while (!TextUtils.isEmpty(parsableWebvttData.readLine())) {}
try {
WebvttParserUtil.validateWebvttHeaderLine(parsableWebvttData);
} catch (ParserException e) {
throw new SubtitleDecoderException(e);
}
while (!TextUtils.isEmpty(parsableWebvttData.readLine())) {
}

int event;
ArrayList<WebvttCue> subtitles = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.novoda.noplayer.internal.exoplayer;

import android.content.Context;

import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;

class BandwidthMeterCreator {
private final Context context;

BandwidthMeterCreator(Context context) {
this.context = context;
}

DefaultBandwidthMeter create(long maxInitialBitrate) {
return new DefaultBandwidthMeter.Builder(context)
.setInitialBitrateEstimate(maxInitialBitrate)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public SimpleExoPlayer create(DrmSessionCreator drmSessionCreator,
);

DefaultLoadControl loadControl = new DefaultLoadControl();
return ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl, drmSessionManager);
return ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector, loadControl, drmSessionManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.net.Uri;
import android.support.annotation.Nullable;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.audio.AudioAttributes;
Expand All @@ -28,6 +29,7 @@ class ExoPlayerFacade {
private static final boolean RESET_POSITION = true;
private static final boolean DO_NOT_RESET_STATE = false;

private final BandwidthMeterCreator bandwidthMeterCreator;
private final AndroidDeviceVersion androidDeviceVersion;
private final MediaSourceFactory mediaSourceFactory;
private final CompositeTrackSelectorCreator trackSelectorCreator;
Expand All @@ -43,11 +45,13 @@ class ExoPlayerFacade {
@Nullable
private Options options;

ExoPlayerFacade(AndroidDeviceVersion androidDeviceVersion,
ExoPlayerFacade(BandwidthMeterCreator bandwidthMeterCreator,
AndroidDeviceVersion androidDeviceVersion,
MediaSourceFactory mediaSourceFactory,
CompositeTrackSelectorCreator trackSelectorCreator,
ExoPlayerCreator exoPlayerCreator,
RendererTypeRequesterCreator rendererTypeRequesterCreator) {
this.bandwidthMeterCreator = bandwidthMeterCreator;
this.androidDeviceVersion = androidDeviceVersion;
this.mediaSourceFactory = mediaSourceFactory;
this.trackSelectorCreator = trackSelectorCreator;
Expand Down Expand Up @@ -109,9 +113,7 @@ void loadVideo(PlayerSurfaceHolder playerSurfaceHolder,
MediaCodecSelector mediaCodecSelector) {
this.options = options;

DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder()
.setInitialBitrateEstimate(options.maxInitialBitrate())
.build();
DefaultBandwidthMeter bandwidthMeter = bandwidthMeterCreator.create(options.maxInitialBitrate());

compositeTrackSelector = trackSelectorCreator.create(options, bandwidthMeter);
exoPlayer = exoPlayerCreator.create(
Expand Down Expand Up @@ -140,7 +142,7 @@ void loadVideo(PlayerSurfaceHolder playerSurfaceHolder,
private void setMovieAudioAttributes(SimpleExoPlayer exoPlayer) {
if (androidDeviceVersion.isLollipopTwentyOneOrAbove()) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(android.media.AudioAttributes.CONTENT_TYPE_MOVIE)
.setContentType(C.CONTENT_TYPE_MOVIE)
.build();
exoPlayer.setAudioAttributes(audioAttributes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ ExoPlayerTwoImpl create(Context context, DrmSessionCreator drmSessionCreator, bo

MediaCodecSelector mediaCodecSelector = downgradeSecureDecoder
? SecurityDowngradingCodecSelector.newInstance()
: MediaCodecSelector.DEFAULT;
: MediaCodecSelector.DEFAULT_WITH_FALLBACK;

CompositeTrackSelectorCreator trackSelectorCreator = new CompositeTrackSelectorCreator();

ExoPlayerCreator exoPlayerCreator = new ExoPlayerCreator(context);
RendererTypeRequesterCreator rendererTypeRequesterCreator = new RendererTypeRequesterCreator();
AndroidDeviceVersion androidDeviceVersion = AndroidDeviceVersion.newInstance();
BandwidthMeterCreator bandwidthMeterCreator = new BandwidthMeterCreator(context);
ExoPlayerFacade exoPlayerFacade = new ExoPlayerFacade(
bandwidthMeterCreator,
androidDeviceVersion,
mediaSourceFactory,
trackSelectorCreator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;

import java.util.List;

class SecurityDowngradingCodecSelector implements MediaCodecSelector {

private static final boolean USE_INSECURE_DECODER = false;
Expand All @@ -20,23 +22,22 @@ public static SecurityDowngradingCodecSelector newInstance() {
}

@Override
public MediaCodecInfo getDecoderInfo(String mimeType, boolean contentRequiresSecureDecoder)
throws MediaCodecUtil.DecoderQueryException {
return internalMediaCodecUtil.getDecoderInfo(mimeType, USE_INSECURE_DECODER);
public List<MediaCodecInfo> getDecoderInfos(String mimeType, boolean requiresSecureDecoder) throws MediaCodecUtil.DecoderQueryException {
return internalMediaCodecUtil.getDecoderInfos(mimeType, USE_INSECURE_DECODER);
}

@Override
public MediaCodecInfo getPassthroughDecoderInfo() {
public MediaCodecInfo getPassthroughDecoderInfo() throws MediaCodecUtil.DecoderQueryException {
return internalMediaCodecUtil.getPassthroughDecoderInfo();
}

static class InternalMediaCodecUtil {

MediaCodecInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder) throws MediaCodecUtil.DecoderQueryException {
return MediaCodecUtil.getDecoderInfo(mimeType, requiresSecureDecoder);
List<MediaCodecInfo> getDecoderInfos(String mimeType, boolean requiresSecureDecoder) throws MediaCodecUtil.DecoderQueryException {
return MediaCodecUtil.getDecoderInfos(mimeType, requiresSecureDecoder);
}

MediaCodecInfo getPassthroughDecoderInfo() {
MediaCodecInfo getPassthroughDecoderInfo() throws MediaCodecUtil.DecoderQueryException {
return MediaCodecUtil.getPassthroughDecoderInfo();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.novoda.noplayer.internal.exoplayer.drm;

import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.google.android.exoplayer2.drm.ExoMediaDrm;
import com.google.android.exoplayer2.drm.MediaDrmCallback;
import com.novoda.noplayer.drm.ModularDrmKeyRequest;
Expand All @@ -28,13 +25,7 @@ public byte[] executeProvisionRequest(UUID uuid, ExoMediaDrm.ProvisionRequest re
}

@Override
public byte[] executeKeyRequest(UUID uuid, ExoMediaDrm.KeyRequest request, @Nullable String mediaProvidedLicenseServerUrl) throws Exception {
String url = request.getDefaultUrl();

if (TextUtils.isEmpty(url)) {
url = mediaProvidedLicenseServerUrl;
}

return streamingModularDrm.executeKeyRequest(new ModularDrmKeyRequest(url, request.getData()));
public byte[] executeKeyRequest(UUID uuid, ExoMediaDrm.KeyRequest request) throws Exception {
return streamingModularDrm.executeKeyRequest(new ModularDrmKeyRequest(request.getLicenseServerUrl(), request.getData()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.google.android.exoplayer2.drm.UnsupportedDrmException;
import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
import com.google.android.exoplayer2.metadata.MetadataDecoderException;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.novoda.noplayer.DetailErrorType;
import com.novoda.noplayer.NoPlayer;
Expand Down Expand Up @@ -62,10 +61,6 @@ static NoPlayer.PlayerError map(Exception rendererException, String message) {
return new NoPlayerError(PlayerErrorType.DEVICE_MEDIA_CAPABILITIES, DetailErrorType.UNKNOWN, message);
}

if (rendererException instanceof MetadataDecoderException) {
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.DECODING_METADATA_ERROR, message);
}

if (rendererException instanceof SubtitleDecoderException) {
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.DECODING_SUBTITLE_ERROR, message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.novoda.noplayer.internal.exoplayer.forwarder;

import android.net.NetworkInfo;
import android.support.annotation.Nullable;
import android.view.Surface;

import com.google.android.exoplayer2.ExoPlaybackException;
Expand Down Expand Up @@ -258,24 +256,14 @@ public void onBandwidthEstimate(EventTime eventTime,
}

@Override
public void onViewportSizeChange(EventTime eventTime, int width, int height) {
public void onSurfaceSizeChanged(EventTime eventTime, int width, int height) {
HashMap<String, String> callingMethodParameters = new HashMap<>();

callingMethodParameters.put(Parameters.EVENT_TIME, eventTime.toString());
callingMethodParameters.put(Parameters.WIDTH, String.valueOf(width));
callingMethodParameters.put(Parameters.HEIGHT, String.valueOf(height));

infoListeners.onNewInfo(Methods.ON_VIEWPORT_SIZE_CHANGE, callingMethodParameters);
}

@Override
public void onNetworkTypeChanged(EventTime eventTime, @Nullable NetworkInfo networkInfo) {
HashMap<String, String> callingMethodParameters = new HashMap<>();

callingMethodParameters.put(Parameters.EVENT_TIME, eventTime.toString());
callingMethodParameters.put(Parameters.NETWORK_INFO, networkInfo == null ? Parameters.NO_NETWORK_INFO : networkInfo.toString());

infoListeners.onNewInfo(Methods.ON_NETWORK_TYPE_CHANGED, callingMethodParameters);
infoListeners.onNewInfo(Methods.ON_SURFACE_SIZE_CHANGED, callingMethodParameters);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ private Parameters() {
static final String BITRATE_ESTIMATE = "bitrateEstimate";
static final String WIDTH = "width";
static final String HEIGHT = "height";
static final String NETWORK_INFO = "networkInfo";
static final String NO_NETWORK_INFO = "null";
static final String METADATA = "metadata";
static final String TRACK_TYPE = "trackType";
static final String DECODER_COUNTERS = "decoderCounters";
Expand All @@ -48,8 +46,6 @@ private Parameters() {
static final String MANIFEST = "manifest";
static final String WINDOW_INDEX = "windowIndex";
static final String MEDIA_PERIOD_ID = "mediaPeriodId";
static final String COUNT = "count";
static final String INITIALIZED_TIMESTAMP_MS = "initializedTimestampMs";

}

Expand Down Expand Up @@ -79,8 +75,7 @@ private Methods() {
static final String ON_MEDIA_PERIOD_RELEASED = "onMediaPeriodReleased";
static final String ON_READING_STARTED = "onReadingStarted";
static final String ON_BANDWIDTH_ESTIMATE = "onBandwidthEstimate";
static final String ON_VIEWPORT_SIZE_CHANGE = "onViewportSizeChange";
static final String ON_NETWORK_TYPE_CHANGED = "onNetworkTypeChanged";
static final String ON_SURFACE_SIZE_CHANGED = "onSurfaceSizeChanged";
static final String ON_METADATA = "onMetadata";
static final String ON_DECODER_ENABLED = "onDecoderEnabled";
static final String ON_DECODER_INITIALIZED = "onDecoderInitialized";
Expand All @@ -97,9 +92,5 @@ private Methods() {
static final String ON_DRM_KEYS_REMOVED = "onDrmKeysRemoved";
static final String ON_LOADING_CHANGED = "onLoadingChanged";
static final String ON_SHUFFLE_MODE_ENABLED_CHANGED = "onShuffleModeEnabledChanged";
static final String ON_VIDEO_ENABLED = "onVideoEnabled";
static final String ON_VIDEO_DECODER_INITIALIZED = "onVideoDecoderInitialized";
static final String ON_VIDEO_INPUT_FORMAT_CHANGED = "onVideoInputFormatChanged";
static final String ON_VIDEO_DISABLED = "onVideoDisabled";
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.novoda.noplayer.internal.exoplayer.forwarder;

import android.net.NetworkInfo;
import android.support.annotation.Nullable;
import android.view.Surface;

import com.google.android.exoplayer2.ExoPlaybackException;
Expand Down Expand Up @@ -195,18 +193,9 @@ public void onBandwidthEstimate(EventTime eventTime,
}

@Override
public void onViewportSizeChange(EventTime eventTime,
int width,
int height) {
public void onSurfaceSizeChanged(EventTime eventTime, int width, int height) {
for (AnalyticsListener listener : listeners) {
listener.onViewportSizeChange(eventTime, width, height);
}
}

@Override
public void onNetworkTypeChanged(EventTime eventTime, @Nullable NetworkInfo networkInfo) {
for (AnalyticsListener listener : listeners) {
listener.onNetworkTypeChanged(eventTime, networkInfo);
listener.onSurfaceSizeChanged(eventTime, width, height);
}
}

Expand Down
Loading

0 comments on commit 5fbb008

Please sign in to comment.