Skip to content
Snippets Groups Projects
Commit 4c6dde3e authored by Ryan Harg's avatar Ryan Harg
Browse files

Merge branch 'feature/65-upgrade-exoplayer' into 'develop'

#65: Upgrade exoplayer version

See merge request !77
parents 565e7e07 00953816
No related branches found
No related tags found
1 merge request!77#65: Upgrade exoplayer version
Pipeline #15966 passed
package audio.funkwhale.ffa.koin package audio.funkwhale.ffa.koin
import android.content.Context import android.content.Context
import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.playback.CacheDataSourceFactoryProvider import audio.funkwhale.ffa.playback.CacheDataSourceFactoryProvider
import audio.funkwhale.ffa.playback.MediaSession import audio.funkwhale.ffa.playback.MediaSession
import audio.funkwhale.ffa.utils.AuthorizationServiceFactory import audio.funkwhale.ffa.utils.AuthorizationServiceFactory
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import com.google.android.exoplayer2.database.DatabaseProvider import com.google.android.exoplayer2.database.DatabaseProvider
import com.google.android.exoplayer2.database.ExoDatabaseProvider import com.google.android.exoplayer2.database.ExoDatabaseProvider
import com.google.android.exoplayer2.offline.DefaultDownloadIndex
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory
import com.google.android.exoplayer2.offline.DownloadManager import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper
import com.google.android.exoplayer2.upstream.cache.Cache import com.google.android.exoplayer2.upstream.cache.Cache
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
import com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor import com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor
...@@ -27,15 +25,12 @@ fun exoplayerModule(context: Context) = module { ...@@ -27,15 +25,12 @@ fun exoplayerModule(context: Context) = module {
single { single {
val cacheDataSourceFactoryProvider = get<CacheDataSourceFactoryProvider>() val cacheDataSourceFactoryProvider = get<CacheDataSourceFactoryProvider>()
DownloaderConstructorHelper(
get(named("exoDownloadCache")), cacheDataSourceFactoryProvider.create(context) val exoDownloadCache = get<Cache>(named("exoDownloadCache"))
).run { val exoDatabase = get<DatabaseProvider>(named("exoDatabase"))
DownloadManager( val cacheDataSourceFactory = cacheDataSourceFactoryProvider.create(context)
context,
DefaultDownloadIndex(get(named("exoDatabase"))), DownloadManager(context, exoDatabase, exoDownloadCache, cacheDataSourceFactory, Runnable::run)
DefaultDownloaderFactory(this)
)
}
} }
single { single {
......
...@@ -9,7 +9,6 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory ...@@ -9,7 +9,6 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
import com.google.android.exoplayer2.upstream.FileDataSource import com.google.android.exoplayer2.upstream.FileDataSource
import com.google.android.exoplayer2.upstream.cache.Cache import com.google.android.exoplayer2.upstream.cache.Cache
import com.google.android.exoplayer2.upstream.cache.CacheDataSource import com.google.android.exoplayer2.upstream.cache.CacheDataSource
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory
import com.google.android.exoplayer2.util.Util import com.google.android.exoplayer2.util.Util
class CacheDataSourceFactoryProvider( class CacheDataSourceFactoryProvider(
...@@ -18,19 +17,19 @@ class CacheDataSourceFactoryProvider( ...@@ -18,19 +17,19 @@ class CacheDataSourceFactoryProvider(
private val exoDownloadCache: Cache private val exoDownloadCache: Cache
) { ) {
fun create(context: Context): CacheDataSourceFactory { fun create(context: Context): CacheDataSource.Factory {
val playbackCache = val playbackCache = CacheDataSource.Factory().apply {
CacheDataSourceFactory(exoCache, createDatasourceFactory(context, oAuth)) setCache(exoCache)
setUpstreamDataSourceFactory(createDatasourceFactory(context, oAuth))
}
return CacheDataSourceFactory( return CacheDataSource.Factory().apply {
exoDownloadCache, setCache(exoDownloadCache)
playbackCache, setUpstreamDataSourceFactory(playbackCache)
FileDataSource.Factory(), setCacheReadDataSourceFactory(FileDataSource.Factory())
null, setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, }
null
)
} }
private fun createDatasourceFactory(context: Context, oAuth: OAuth): DataSource.Factory { private fun createDatasourceFactory(context: Context, oAuth: OAuth): DataSource.Factory {
......
...@@ -3,11 +3,7 @@ package audio.funkwhale.ffa.playback ...@@ -3,11 +3,7 @@ package audio.funkwhale.ffa.playback
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import com.google.android.exoplayer2.upstream.DataSource import com.google.android.exoplayer2.upstream.*
import com.google.android.exoplayer2.upstream.DataSpec
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
import com.google.android.exoplayer2.upstream.HttpDataSource
import com.google.android.exoplayer2.upstream.TransferListener
class OAuthDatasource( class OAuthDatasource(
private val context: Context, private val context: Context,
...@@ -15,11 +11,11 @@ class OAuthDatasource( ...@@ -15,11 +11,11 @@ class OAuthDatasource(
private val oauth: OAuth private val oauth: OAuth
) : DataSource { ) : DataSource {
override fun addTransferListener(transferListener: TransferListener?) { override fun addTransferListener(transferListener: TransferListener) {
http.addTransferListener(transferListener) http.addTransferListener(transferListener)
} }
override fun open(dataSpec: DataSpec?): Long { override fun open(dataSpec: DataSpec): Long {
oauth.tryRefreshAccessToken(context) oauth.tryRefreshAccessToken(context)
http.apply { http.apply {
setRequestProperty("Authorization", "Bearer ${oauth.state().accessToken}") setRequestProperty("Authorization", "Bearer ${oauth.state().accessToken}")
...@@ -27,7 +23,7 @@ class OAuthDatasource( ...@@ -27,7 +23,7 @@ class OAuthDatasource(
return http.open(dataSpec) return http.open(dataSpec)
} }
override fun read(buffer: ByteArray?, offset: Int, readLength: Int): Int { override fun read(buffer: ByteArray, offset: Int, readLength: Int): Int {
return http.read(buffer, offset, readLength) return http.read(buffer, offset, readLength)
} }
......
...@@ -3,7 +3,7 @@ package audio.funkwhale.ffa.playback ...@@ -3,7 +3,7 @@ package audio.funkwhale.ffa.playback
import android.app.Notification import android.app.Notification
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import androidx.core.net.toUri
import audio.funkwhale.ffa.R import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.model.DownloadInfo import audio.funkwhale.ffa.model.DownloadInfo
import audio.funkwhale.ffa.model.Track import audio.funkwhale.ffa.model.Track
...@@ -42,16 +42,12 @@ class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) { ...@@ -42,16 +42,12 @@ class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) {
) )
).toByteArray() ).toByteArray()
DownloadRequest( val request = DownloadRequest.Builder(track.id.toString(), url.toUri())
url, .setData(data)
DownloadRequest.TYPE_PROGRESSIVE, .setStreamKeys(Collections.emptyList())
Uri.parse(url), .build()
Collections.emptyList(),
null, sendAddDownload(context, PinService::class.java, request, false)
data
).also {
sendAddDownload(context, PinService::class.java, it, false)
}
} }
} }
} }
...@@ -83,14 +79,19 @@ class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) { ...@@ -83,14 +79,19 @@ class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) {
return DownloadNotificationHelper( return DownloadNotificationHelper(
this, this,
AppContext.NOTIFICATION_CHANNEL_DOWNLOADS AppContext.NOTIFICATION_CHANNEL_DOWNLOADS
).buildProgressNotification(R.drawable.downloads, null, description, downloads) ).buildProgressNotification(this, R.drawable.downloads, null, description, downloads)
} }
private fun getDownloads() = downloadManager.downloadIndex.getDownloads() private fun getDownloads() = downloadManager.downloadIndex.getDownloads()
inner class DownloadListener : DownloadManager.Listener { inner class DownloadListener : DownloadManager.Listener {
override fun onDownloadChanged(downloadManager: DownloadManager, download: Download) {
super.onDownloadChanged(downloadManager, download) override fun onDownloadChanged(
downloadManager: DownloadManager,
download: Download,
finalException: Exception?
) {
super.onDownloadChanged(downloadManager, download, finalException)
EventBus.send(Event.DownloadChanged(download)) EventBus.send(Event.DownloadChanged(download))
} }
......
...@@ -476,10 +476,13 @@ class PlayerService : Service() { ...@@ -476,10 +476,13 @@ class PlayerService : Service() {
CommandBus.send(Command.RefreshTrack(queue.current())) CommandBus.send(Command.RefreshTrack(queue.current()))
} }
override fun onPositionDiscontinuity(reason: Int) { override fun onPositionDiscontinuity(
super.onPositionDiscontinuity(reason) oldPosition: Player.PositionInfo,
newPosition: Player.PositionInfo,
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) { reason: Int
) {
super.onPositionDiscontinuity(oldPosition, newPosition, reason)
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
val currentTrack = queue.current().also { val currentTrack = queue.current().also {
it.log("Track finished") it.log("Track finished")
} }
......
...@@ -4,8 +4,8 @@ object Versions { ...@@ -4,8 +4,8 @@ object Versions {
const val unmock = "0.7.8" const val unmock = "0.7.8"
const val gradleDependencyPlugin = "0.38.0" const val gradleDependencyPlugin = "0.38.0"
const val exoPlayer = "2.11.8" const val exoPlayer = "2.14.2"
const val exoPlayerExtensions = "2.11.4" const val exoPlayerExtensions = "2.14.0"
const val fuel = "2.3.1" const val fuel = "2.3.1"
const val gson = "2.8.7" const val gson = "2.8.7"
const val powerPreference = "2.0.0" const val powerPreference = "2.0.0"
......
Upgrade ExoPlayer version to 2.14.2 (#65)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment