google / google/ExoPlayer

Android Auto queue list refresh

Open
#7,831 13 comments 2 reactions 1 assignee Claimed by @marcbaechinger View on GitHub
enhancement
Dominant language
Java
Stars
21.9k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi,

[Preview 1](https://github.com/orcunkobal/test/blob/master/1.gif)
[Preview 2](https://github.com/orcunkobal/test/blob/master/2.gif)

We decided to support Android auto and it almost finished. But we have several problems. Our problem is happening on **live stream(HLS)** lists. Our music service accepts two types which are radios and podcasts. When the MainActivity was created it bound to the music service. The service roughly like that;

```
fun startService(){
concatenatingMediaSources.addMediaSources(createMediaSourceList(playlist))
player.setAudioAttributes(getAudioAttributes(), true)
player.repeatMode = getPlaylistRepeatMode()

player.prepare(concatenatingMediaSources)
player.seekTo(playingIndex, C.TIME_UNSET)
player.playWhenReady = true

prepareNotification()
mMediaSessionConnector.setQueueNavigator(TimeLineQueuNavigator())
}

private fun createMediaSourceList(playlist: ArrayList): ArrayList {
if (concatenatingMediaSources.size > 0) concatenatingMediaSources.clear()
val mediaSource = ArrayList()
val list = playlist.iterator()
while (list.hasNext()) {
val playlistItem = list.next()
if (playlistItem.isRadio) {
mediaSource.add(buildMediaSource(isHLS = playlistItem.isHls, tag = playlistItem.id
?: 0, media = playlistItem.media?.get(0).toString()))
} else {
mediaSource.add(buildMediaSource(isHLS = false, tag = playlistItem.id
?: 0, media = playlistItem.media?.get(0).toString()))
}
}
return mediaSource
}

private fun buildMediaSource(isHLS: Boolean, tag: Int, media: String): MediaSource {
return if (isHLS) {
val mediaSource = HlsMediaSource.Factory(hlsDataSourceFactory)
.setTag(tag)
.createMediaSource(Uri.parse(media))
mediaSource
} else {
val mediaSource = ProgressiveMediaSource.Factory(defaultDataSourceFactory)
.setTag(tag)
.createMediaSource(Uri.parse(media))
mediaSource
}
}

```
If the coming data is the HLS radio list my queue is always refreshing. For example, I connect to the Android Auto from use DHU and play the radio list then I click the queue button from the player and I want to explore all lists but when I want to scroll down it's always selected to the playing item. That's why I can't explore the queue list. As if always notifydatasetchanged() is running on the background. Also, the PlayerNotificationManager -> MediaDescriptionAdapter and the TimelineQueueNavigator > getMediaDescription is fired endless.

I wanted to be sure If I’m wrong. I cloned the UAMP project and changed MediaMetaDataCompactEx.kt

from:

```
fun MediaMetadataCompat.toMediaSource(dataSourceFactory: DataSource.Factory) =
ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaUri)
```

to:

```
fun MediaMetadataCompat.toMediaSource(dataSourceFactory: DataSource.Factory) =
HlsMediaSource.Factory(DefaultHlsDataSourceFactory(dataSourceFactory))
.setTag("test")
.createMediaSource(Uri.parse("https://.../128/playlist.m3u8"))
```

The same thing happened there. The queue is not explorable because when I want to scroll down the queue scroll position changes because it’s refreshing some way.

I’m waiting for advice from you about how should I solve this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.