Skip to content

Commit

Permalink
Isolate out exoplayer ParserException
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Karia committed Oct 16, 2024
1 parent 48ed722 commit 582404e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ class ConnectivityException(cause: Exception)
override val errorCode: Int = 206
}

class ParsingException(cause: Exception)
: ArmadilloException(cause = cause, message = "The content cannot be parsed and it is not playable: ${cause.message}") {
override val errorCode = 207
}

/**
* Download Errors
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.scribd.armadillo.playback
import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.ExoPlaybackException.TYPE_RENDERER
import com.google.android.exoplayer2.ExoPlaybackException.TYPE_SOURCE
import com.google.android.exoplayer2.ParserException
import com.google.android.exoplayer2.audio.AudioSink
import com.google.android.exoplayer2.drm.MediaDrmCallbackException
import com.google.android.exoplayer2.upstream.DataSpec
Expand All @@ -11,11 +12,13 @@ import com.scribd.armadillo.error.ArmadilloException
import com.scribd.armadillo.error.ArmadilloIOException
import com.scribd.armadillo.error.ConnectivityException
import com.scribd.armadillo.error.HttpResponseCodeException
import com.scribd.armadillo.error.ParsingException
import com.scribd.armadillo.error.RendererConfigurationException
import com.scribd.armadillo.error.RendererInitializationException
import com.scribd.armadillo.error.RendererWriteException
import com.scribd.armadillo.error.UnexpectedException
import com.scribd.armadillo.error.UnknownRendererException
import java.io.IOException
import java.net.SocketTimeoutException
import java.net.UnknownHostException

Expand All @@ -38,7 +41,16 @@ internal fun ExoPlaybackException.toArmadilloException(): ArmadilloException {
is UnknownHostException,
is SocketTimeoutException -> ConnectivityException(source)

else -> ArmadilloIOException(cause = this, actionThatFailedMessage = "Exoplayer error.")
else -> {
var cause: Throwable? = source
while (source.cause != null && cause !is ParserException) {
cause = source.cause
}
when (cause) {
is ParserException -> ParsingException(cause = this)
else -> ArmadilloIOException(cause = this, actionThatFailedMessage = "Exoplayer error.")
}
}
}
}
} else if (TYPE_RENDERER == type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class DownloadManagerExtKtTest {
}

private lateinit var downloadState: TestableDownloadState

@Before
fun setUp() {
downloadState = TestableDownloadState(
ID,
URL,
TestableDownloadState.COMPLETED,
DOWNLOAD_PERCENT,
DOWNLOADED_BYTES)
ID,
URL,
TestableDownloadState.COMPLETED,
DOWNLOAD_PERCENT,
DOWNLOADED_BYTES)
}

@Test
Expand All @@ -35,7 +36,7 @@ class DownloadManagerExtKtTest {
@Test
fun toDownloadInfo_downloadRemovalComplete_returnsRemoveProgress() {
val state = downloadState.copy(
state = TestableDownloadState.REMOVING)
state = TestableDownloadState.REMOVING)
val downloadInfo = state.toDownloadInfo()!!
assertThat(downloadInfo.id).isEqualTo(ID)
assertThat(downloadInfo.url).isEqualTo(URL)
Expand All @@ -45,7 +46,7 @@ class DownloadManagerExtKtTest {
@Test
fun toDownloadInfo_downloadComplete_returnsCompletedProgress() {
val state = downloadState.copy(
state = TestableDownloadState.COMPLETED)
state = TestableDownloadState.COMPLETED)
val downloadInfo = state.toDownloadInfo()!!
assertThat(downloadInfo.id).isEqualTo(ID)
assertThat(downloadInfo.url).isEqualTo(URL)
Expand All @@ -55,8 +56,8 @@ class DownloadManagerExtKtTest {
@Test
fun toDownloadInfo_downloadProgressJustBegan_returnsProgress() {
val state = downloadState.copy(
state = TestableDownloadState.IN_PROGRESS,
downloadPercentage = DownloadProgressInfo.PROGRESS_UNSET)
state = TestableDownloadState.IN_PROGRESS,
downloadPercentage = DownloadProgressInfo.PROGRESS_UNSET)
val downloadInfo = state.toDownloadInfo()!!
assertThat(downloadInfo.id).isEqualTo(ID)
assertThat(downloadInfo.url).isEqualTo(URL)
Expand All @@ -66,7 +67,7 @@ class DownloadManagerExtKtTest {
@Test
fun toDownloadInfo_downloadProgressWithProgress_returnsProgress() {
val state = downloadState.copy(
state = TestableDownloadState.IN_PROGRESS)
state = TestableDownloadState.IN_PROGRESS)
val downloadInfo = state.toDownloadInfo()!!
assertThat(downloadInfo.id).isEqualTo(ID)
assertThat(downloadInfo.url).isEqualTo(URL)
Expand All @@ -76,10 +77,10 @@ class DownloadManagerExtKtTest {
@Test
fun toDownloadInfo_unknownState_returnsFailed() {
val state = downloadState.copy(
state = 1000)
state = 1000)
val downloadInfo = state.toDownloadInfo()!!
assertThat(downloadInfo.id).isEqualTo(ID)
assertThat(downloadInfo.url).isEqualTo(URL)
assertThat(downloadInfo.downloadState).isEqualTo(DownloadState.FAILED)
assertThat(downloadInfo.downloadState).isEqualTo(DownloadState.FAILED())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ExoplayerDownloadTrackerTest {

@Test
fun dispatchActionsForProgress_taskFailed_dispatchesActions() {
downloadInfo = DownloadProgressInfo(ID, URL, DownloadState.FAILED)
downloadInfo = DownloadProgressInfo(ID, URL, DownloadState.FAILED())
exoplayerDownloadTracker.dispatchActionsForProgress(downloadInfo)
verify(stateModifier).dispatch(UpdateDownloadAction(downloadInfo))
verify(stateModifier).dispatch(isA<ErrorAction>())
Expand Down

0 comments on commit 582404e

Please sign in to comment.