How to dynamically change the audio url using media3 exoplayer?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
I use media3 exoplayer to develop a music playback APP. Since the audio URL will become invalid, I need to request a new URL and replace it after it expires.
As follows
val upstreamFactory = ResolvingDataSource.Factory(
DefaultHttpDataSource.Factory()
) {
// replace url here when needed
dataSpec -> dataSpec.withUri(dataSpec.uri)
}
val myDataSourceFactory = CacheDataSource.Factory()
.setCache(myLocalCache)
.setUpstreamDataSourceFactory(upstreamFactory)
.setCacheWriteDataSinkFactory(null)
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
val myMediaSourceFactory = DefaultMediaSourceFactory(this).setDataSourceFactory(myDataSourceFactory)
ExoPlayer.Builder(this).apply {
setMediaSourceFactory(myMediaSourceFactory)
}.build()
When the url is invalid, replace it with a new url through ResolvingDataSource.
But there is a problem. When the URL is replaced, the player will stop playing after a while.
There's no obvious error logs. In DefaultHttpDataSource, the open(DataSpec dataSpec) method is executed and the connection is established.
I guess CacheDataSource did a check and found that the two URLs were different or the container meta information was different, so it stopped. I'm not sure.
Is there a solution?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.