From e79a829736a8c16741e77bcf5d7b141ead6f0973 Mon Sep 17 00:00:00 2001 From: Philip Simpson Date: Thu, 28 Jul 2022 09:51:49 +0530 Subject: [PATCH 1/3] Upgrade exoplayer to 2.18.2 --- dependencies.gradle | 2 +- .../profile/cloud/AddFileActivity.kt | 11 ++++------- .../playback/EpisodeFileMetadata.kt | 18 +++++++++--------- .../playback/ShiftyAudioProcessorChain.kt | 5 +++-- .../playback/ShiftyRenderersFactory.kt | 14 +++++++------- .../repositories/playback/SimplePlayer.kt | 8 +++----- 6 files changed, 27 insertions(+), 31 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 98d654a6c2e..6502afd34fd 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -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' diff --git a/modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/cloud/AddFileActivity.kt b/modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/cloud/AddFileActivity.kt index 2852fbff0af..711f02c5c7e 100644 --- a/modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/cloud/AddFileActivity.kt +++ b/modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/cloud/AddFileActivity.kt @@ -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 @@ -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) @@ -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 } diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/EpisodeFileMetadata.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/EpisodeFileMetadata.kt index 7418ecd9db9..9e81af0cc7b 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/EpisodeFileMetadata.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/EpisodeFileMetadata.kt @@ -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 @@ -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() 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) { diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/ShiftyAudioProcessorChain.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/ShiftyAudioProcessorChain.kt index 814417b2af1..7c8263d8862 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/ShiftyAudioProcessorChain.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/ShiftyAudioProcessorChain.kt @@ -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, diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/ShiftyRenderersFactory.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/ShiftyRenderersFactory.kt index c68febad94c..34dac942ca6 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/ShiftyRenderersFactory.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/ShiftyRenderersFactory.kt @@ -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( diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/SimplePlayer.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/SimplePlayer.kt index b98e5f32a28..be7bfecebc7 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/SimplePlayer.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/SimplePlayer.kt @@ -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 @@ -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) } From dcdd220adda87ada152ca5434dcd13225c2c89cb Mon Sep 17 00:00:00 2001 From: ashiagr Date: Tue, 17 Jan 2023 13:13:30 +0530 Subject: [PATCH 2/3] Fix instrumented tests --- base.gradle | 1 + dependencies.gradle | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/base.gradle b/base.gradle index 33d4e39a528..d593d89154e 100644 --- a/base.gradle +++ b/base.gradle @@ -282,6 +282,7 @@ dependencies { androidTestImplementation(libs.barista) { exclude group: 'org.jetbrains.kotlin' } + androidTestImplementation androidLibs.accessibilityTestFramework coreLibraryDesugaring androidLibs.desugarJdk } diff --git a/dependencies.gradle b/dependencies.gradle index 6502afd34fd..be8430c5031 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -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' @@ -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 = [ From 69148740b6ef49ed03ca862e80002747a1a837cb Mon Sep 17 00:00:00 2001 From: ashiagr Date: Tue, 17 Jan 2023 13:54:50 +0530 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb7eba52d12..382b09919e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)).