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

ALL-3936/Error classes #64

Merged
merged 5 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 22 additions & 0 deletions core/src/main/java/com/novoda/noplayer/NoPlayerError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.novoda.noplayer;

public class NoPlayerError implements Player.PlayerError {

private final PlayerErrorType playerErrorType;
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

private final Throwable cause;

public NoPlayerError(PlayerErrorType playerErrorType, Throwable cause) {
this.playerErrorType = playerErrorType;
this.cause = cause;
}

@Override
public PlayerErrorType getType() {
return playerErrorType;
}

@Override
public Throwable getCause() {
return cause;
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/com/novoda/noplayer/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public interface Player extends PlayerState {

interface PlayerError {

String getType();
PlayerErrorType getType();

Throwable getCause();
}
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/com/novoda/noplayer/PlayerErrorType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.novoda.noplayer;

public enum PlayerErrorType {

INVALID_RESPONSE_CODE,
MALFORMED_CONTENT,
FAILED_DRM_DECRYPTION,
FAILED_DRM_INITIATING,
FAILED_DRM_REQUEST,
CONNECTIVITY_ERROR,
MEDIA_FORMAT_NOT_RECOGNISED,
Copy link
Contributor

Choose a reason for hiding this comment

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

RECOGNIZED 🇺🇸

MEDIA_SERVER_DIED,
MEDIA_SOURCE_ERROR,
STREAMED_VIDEO_ERROR,
UNKNOWN
Copy link
Contributor

Choose a reason for hiding this comment

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

@Dorvaryn disappointed to not find UNKOWN


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.novoda.noplayer.internal.exoplayer.forwarder;

import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
import com.novoda.noplayer.NoPlayerError;
import com.novoda.noplayer.Player;
import com.novoda.noplayer.internal.exoplayer.playererror.DrmInitiatingError;
import com.novoda.noplayer.PlayerErrorType;

class DrmSessionErrorForwarder implements DefaultDrmSessionManager.EventListener {

Expand All @@ -19,7 +20,7 @@ public void onDrmKeysLoaded() {

@Override
public void onDrmSessionManagerError(Exception e) {
Player.PlayerError playerError = new DrmInitiatingError(e);
Player.PlayerError playerError = new NoPlayerError(PlayerErrorType.FAILED_DRM_INITIATING, e);
errorListener.onError(playerError);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.novoda.noplayer.NoPlayerError;
import com.novoda.noplayer.Player;
import com.novoda.noplayer.PlayerErrorType;
import com.novoda.noplayer.drm.StreamingModularDrm;
import com.novoda.noplayer.internal.exoplayer.playererror.ConnectivityError;
import com.novoda.noplayer.internal.exoplayer.playererror.DrmDecryptionError;
import com.novoda.noplayer.internal.exoplayer.playererror.DrmRequestError;
import com.novoda.noplayer.internal.exoplayer.playererror.InvalidResponseCodeError;
import com.novoda.noplayer.internal.exoplayer.playererror.MalformedContentError;
import com.novoda.noplayer.internal.exoplayer.playererror.UnknownError;

import java.io.IOException;

Expand All @@ -23,22 +19,25 @@ private ExoPlayerErrorMapper() {

static Player.PlayerError errorFor(Exception e) {
if (e instanceof HttpDataSource.InvalidResponseCodeException) {
return new InvalidResponseCodeError(e);
return new NoPlayerError(PlayerErrorType.INVALID_RESPONSE_CODE, e);
}

if (e instanceof ParserException) {
return new MalformedContentError(e);
return new NoPlayerError(PlayerErrorType.MALFORMED_CONTENT, e);
}

Throwable cause = e.getCause();
if (e.getCause() instanceof MediaCodec.CryptoException) {
return new DrmDecryptionError(e);
return new NoPlayerError(PlayerErrorType.FAILED_DRM_DECRYPTION, e);
}

if (cause instanceof StreamingModularDrm.DrmRequestException) {
return new DrmRequestError(cause);
return new NoPlayerError(PlayerErrorType.FAILED_DRM_REQUEST, e);
}

if (e instanceof IOException || cause instanceof IOException) {
return new ConnectivityError(cause == null ? e : cause);
return new NoPlayerError(PlayerErrorType.CONNECTIVITY_ERROR, cause == null ? e : cause);
}
return new UnknownError(e);
return new NoPlayerError(PlayerErrorType.UNKNOWN, e);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.novoda.noplayer.internal.exoplayer.forwarder;

import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.novoda.noplayer.NoPlayerError;
import com.novoda.noplayer.Player;
import com.novoda.noplayer.internal.exoplayer.playererror.MediaSourceError;
import com.novoda.noplayer.PlayerErrorType;

import java.io.IOException;

Expand All @@ -16,7 +17,7 @@ class MediaSourceOnErrorForwarder implements ExtractorMediaSource.EventListener

@Override
public void onLoadError(IOException error) {
Player.PlayerError playerError = new MediaSourceError(error);
Player.PlayerError playerError = new NoPlayerError(PlayerErrorType.MEDIA_SOURCE_ERROR, error);
errorListener.onError(playerError);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading