Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade exoplayer to 2.18.2 #707

Merged
merged 4 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Health:
* Switched to using the new user login and register endpoints.
([#685](https://github.com/Automattic/pocket-casts-android/pull/685)).
* Upgraded ExoPlayer to 2.18.2
([#707](https://github.com/Automattic/pocket-casts-android/pull/707)).
* New Features:
* Add support for HLS streams
([#679](https://github.com/Automattic/pocket-casts-android/pull/679)).
Expand Down
1 change: 1 addition & 0 deletions base.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ dependencies {
androidTestImplementation(libs.barista) {
exclude group: 'org.jetbrains.kotlin'
}
androidTestImplementation androidLibs.accessibilityTestFramework

coreLibraryDesugaring androidLibs.desugarJdk
}
7 changes: 5 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ project.ext {
versionComposeCompiler = '1.3.0'
versionDagger = '2.41'
versionEspresso = '3.4.0'
versionExoplayer = '2.16.1'
versionExoplayer = '2.18.2'
versionGlide = '4.13.2'
versionHilt = '2.43.2'
versionKotlinCoroutines = '1.6.4'
Expand All @@ -96,6 +96,7 @@ project.ext {
versionRoom = '2.4.3'
versionTest = '1.4.0'
versionWork = '2.7.1'
versionAccessibilityTestFramework = '4.0.0'

// Automattic library versions
versionTracks = 'trunk-b3655d42123501a1d9a304789b738610ab4403c8'
Expand Down Expand Up @@ -171,7 +172,9 @@ project.ext {
composeRx: "androidx.compose.runtime:runtime-rxjava2:$versionCompose",
composeViewModel: "androidx.lifecycle:lifecycle-viewmodel-compose:$versionLifecycle",
composeUiUtil: "androidx.compose.ui:ui-util:$versionCompose",
guava: 'com.google.guava:guava:27.1-android' // Required to fix conflict between versions in exoplayer and workmanager
guava: 'com.google.guava:guava:27.1-android', // Required to fix conflict between versions in exoplayer and workmanager
// Fixes instrumentation tests, see: https://github.com/android/android-test/issues/861#issuecomment-1180219978
accessibilityTestFramework: "com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:$versionAccessibilityTestFramework"
]

libs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ import com.google.android.exoplayer2.DefaultLoadControl
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.Tracks
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.extractor.mp3.Mp3Extractor
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.source.TrackGroupArray
import com.google.android.exoplayer2.trackselection.TrackSelectionArray
import com.google.android.exoplayer2.upstream.DefaultDataSource
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -672,10 +671,9 @@ class AddFileActivity :
val loadControl = DefaultLoadControl.Builder().setBufferDurationsMs(0, 0, 0, 0).build()
val player = ExoPlayer.Builder(this).setLoadControl(loadControl).build()
player.addListener(object : Player.Listener {
@Deprecated("Deprecated. Use onTracksInfoChanged(TracksInfo) instead.")
override fun onTracksChanged(trackGroups: TrackGroupArray, trackSelections: TrackSelectionArray) {
override fun onTracksChanged(tracks: Tracks) {
val episodeMetadata = EpisodeFileMetadata()
episodeMetadata.read(trackSelections, true, this@AddFileActivity)
episodeMetadata.read(tracks, true, this@AddFileActivity)
episodeMetadata.embeddedArtworkPath?.let {
val artworkUri = Uri.parse(it)
loadImageFromUri(artworkUri, isFile = true)
Expand All @@ -690,8 +688,7 @@ class AddFileActivity :
}
}

@Deprecated("Deprecated. Use onPlaybackStateChanged(int) and onPlayWhenReadyChanged(boolean, int) instead.")
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
override fun onPlaybackStateChanged(@Player.State playbackState: Int) {
if (playbackState == ExoPlayer.STATE_READY) {
length = player.duration
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import android.graphics.BitmapFactory
import au.com.shiftyjelly.pocketcasts.models.to.Chapter
import au.com.shiftyjelly.pocketcasts.models.to.Chapters
import au.com.shiftyjelly.pocketcasts.preferences.Settings
import com.google.android.exoplayer2.Tracks
import com.google.android.exoplayer2.metadata.id3.ApicFrame
import com.google.android.exoplayer2.metadata.id3.ChapterFrame
import com.google.android.exoplayer2.metadata.id3.TextInformationFrame
import com.google.android.exoplayer2.metadata.id3.UrlLinkFrame
import com.google.android.exoplayer2.trackselection.TrackSelectionArray
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import timber.log.Timber
import java.io.BufferedOutputStream
Expand All @@ -36,22 +36,22 @@ class EpisodeFileMetadata(val filenamePrefix: String? = null) {
var embeddedTitle: String? = null
var embeddedLength: Long? = null

fun read(trackSelections: TrackSelectionArray?, settings: Settings, context: Context) {
return read(trackSelections, settings.getUseEmbeddedArtwork(), context)
fun read(tracks: Tracks?, settings: Settings, context: Context) {
return read(tracks, settings.getUseEmbeddedArtwork(), context)
}

fun read(trackSelections: TrackSelectionArray?, loadArtwork: Boolean, context: Context) {
fun read(tracks: Tracks?, loadArtwork: Boolean, context: Context) {
val newChapters = mutableListOf<Chapter>()
embeddedArtworkPath = null

if (trackSelections == null) {
if (tracks == null) {
return
}
try {
for (i in 0 until trackSelections.length) {
val selection = trackSelections.get(i) ?: continue
for (j in 0 until selection.length()) {
val metadata = selection.getFormat(j).metadata ?: continue
for (i in 0 until tracks.groups.size) {
val group = tracks.groups[i] ?: continue
for (j in 0 until tracks.groups.size) {
val metadata = group.getTrackFormat(j).metadata ?: continue
for (k in 0 until metadata.length()) {
val frame = metadata.get(k)
if (frame is ChapterFrame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package au.com.shiftyjelly.pocketcasts.repositories.playback
import au.com.shiftyjelly.pocketcasts.models.type.TrimMode
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.audio.AudioProcessor
import com.google.android.exoplayer2.audio.DefaultAudioSink.AudioProcessorChain
import com.google.android.exoplayer2.audio.AudioProcessorChain
import com.google.android.exoplayer2.audio.SonicAudioProcessor
import timber.log.Timber

internal class ShiftyAudioProcessorChain(private val customAudio: ShiftyCustomAudio) : AudioProcessorChain {
internal class ShiftyAudioProcessorChain(private val customAudio: ShiftyCustomAudio) :
AudioProcessorChain {
private val lowProcessor = ShiftyTrimSilenceProcessor(
this::onSkippedFrames,
416000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class ShiftyRenderersFactory(context: Context?, statsManager: StatsManager, priv

override fun buildAudioSink(context: Context, enableFloatOutput: Boolean, enableAudioTrackPlaybackParams: Boolean, enableOffload: Boolean): AudioSink {
processorChain = ShiftyAudioProcessorChain(customAudio)
return DefaultAudioSink(
AudioCapabilities.getCapabilities(context),
processorChain!!,
enableFloatOutput,
enableAudioTrackPlaybackParams,
if (enableOffload) DefaultAudioSink.OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED else DefaultAudioSink.OFFLOAD_MODE_DISABLED
)
return DefaultAudioSink.Builder()
.setAudioCapabilities(AudioCapabilities.getCapabilities(context))
.setAudioProcessorChain(processorChain!!)
.setEnableFloatOutput(enableFloatOutput)
.setEnableAudioTrackPlaybackParams(enableAudioTrackPlaybackParams)
.setOffloadMode(if (enableOffload) DefaultAudioSink.OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED else DefaultAudioSink.OFFLOAD_MODE_DISABLED)
.build()
}

override fun buildAudioRenderers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.Tracks
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.extractor.mp3.Mp3Extractor
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.source.TrackGroupArray
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.trackselection.TrackSelectionArray
import com.google.android.exoplayer2.upstream.DefaultDataSource
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.video.VideoSize
Expand Down Expand Up @@ -199,10 +198,9 @@ class SimplePlayer(val settings: Settings, val statsManager: StatsManager, val c

setPlayerEffects()
player.addListener(object : Player.Listener {
@Deprecated("Deprecated. Use onTracksInfoChanged(TracksInfo) instead.")
override fun onTracksChanged(trackGroups: TrackGroupArray, trackSelections: TrackSelectionArray) {
override fun onTracksChanged(tracks: Tracks) {
val episodeMetadata = EpisodeFileMetadata(filenamePrefix = episodeUuid)
episodeMetadata.read(trackSelections, settings, context)
episodeMetadata.read(tracks, settings, context)
onMetadataAvailable(episodeMetadata)
}

Expand Down