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

DataSourceFactory with OkHttpDataSource ignored #116

Closed
1 task
Nucifera8472 opened this issue Jul 12, 2022 · 2 comments
Closed
1 task

DataSourceFactory with OkHttpDataSource ignored #116

Nucifera8472 opened this issue Jul 12, 2022 · 2 comments
Assignees
Labels

Comments

@Nucifera8472
Copy link

Media3 Version

1.0.0-beta01

Devices that reproduce the issue

  • Samsung Galaxy A52s
  • bq Aquaris X Pro

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

I am trying to switch the network stack to OkHttp as described in the Exoplayer documentation. The player instance is created inside a MediaSessionService with a custom mediaSourceFactory containing the OkHttpDataSouce like so:

        player = ExoPlayer.Builder(baseContext)
            .setMediaSourceFactory(
                DefaultMediaSourceFactory(baseContext)
                    .setDataSourceFactory {
                        // this code is never called -----------------------------------------------
                        OkHttpDataSource.Factory(okHttpClient).createDataSource() 
                    }
            )
            .build()

The mediaSource is never directly set anywhere else in the code, the only interaction is via the mediaController which I use to set MediaItem playlists.

          val requestMetadata = MediaItem.RequestMetadata.Builder()
              .setMediaUri(item.url.toUri())
              .build()
          val mediaItem = MediaItem.Builder()
              .setMediaId(item.id)
              .setRequestMetadata(requestMetadata)
              .build()
        val mediaItems = listOf(mediaItem)  // playlist generation code omitted for brevity
        mediaController?.setMediaItems(mediaItems, startIndex, C.TIME_UNSET)

Expected result

Player is expected to use the provided OkHttpClient for network connection.

Actual result

According to the logs, the player is still using DefaultHttpDataSource for communication instead of the provided OkHttpDataSource. The line of code where the actual data source creation by the factory would happen never gets called.

The reason I am trying to switch the network stack is that some of the online radio URLs that I try to play return 301 or 302 HTTP status codes. While information I found suggests that redirects should be working, I thought that maybe the DefaultHttpDataSource is one that doesn't handle it well at that OkHttp would handle it better. And if not I at least wanted to find out what is going on in the redirect which I thought would be easy by using an OkHttpClient with a logging interceptor. I also tried enabling cross protocol redirects (setAllowCrossProtocolRedirects(true) ) on the DefaultHttpDataSource, but it didn't work - which I assume is also caused by the datasource being ignored.

DefaultMediaSourceFactory(baseContext)
    .setDataSourceFactory(
        DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true)
    )

Media

The issue isn't caused by any specific media type, but that's the one I was testing it with:

Original URL http://stream.mangoradio.de/ (ERROR_CODE_IO_BAD_HTTP_STATUS, HTTP 301)
Redirected URL https://stream.laut.fm/mangoradio (this one plays just fine)

Bug Report

  • You will email the zip file produced by adb bugreport to [email protected] after filing this issue.
@tonihei
Copy link
Collaborator

tonihei commented Jul 12, 2022

Thanks for reporting! We discovered the same bug ourselves yesterday and it will be fixed soon.

@tonihei tonihei self-assigned this Jul 12, 2022
rohitjoins pushed a commit that referenced this issue Jul 13, 2022
The call doesn't currently reset the already loaded suppliers and
factories. Also fix the supplier loading code to use a local copy
of the current dataSourceFactory to avoid leaking an updated
instance to a later invocation.

Issue: #116

#minor-release

PiperOrigin-RevId: 460721541
rohitjoins pushed a commit to google/ExoPlayer that referenced this issue Jul 13, 2022
The call doesn't currently reset the already loaded suppliers and
factories. Also fix the supplier loading code to use a local copy
of the current dataSourceFactory to avoid leaking an updated
instance to a later invocation.

Issue: androidx/media#116

#minor-release

PiperOrigin-RevId: 460721541
@tonihei
Copy link
Collaborator

tonihei commented Jul 15, 2022

Fix by the commit above, will be released soon in ExoPlayer 2.18.1 / Media3 1.0.0-beta02.

@tonihei tonihei closed this as completed Jul 15, 2022
rohitjoins pushed a commit to google/ExoPlayer that referenced this issue Jul 15, 2022
The call doesn't currently reset the already loaded suppliers and
factories. Also fix the supplier loading code to use a local copy
of the current dataSourceFactory to avoid leaking an updated
instance to a later invocation.

Issue: androidx/media#116

#minor-release

PiperOrigin-RevId: 460721541
(cherry picked from commit 6be0d6e)
rohitjoins pushed a commit that referenced this issue Jul 15, 2022
The call doesn't currently reset the already loaded suppliers and
factories. Also fix the supplier loading code to use a local copy
of the current dataSourceFactory to avoid leaking an updated
instance to a later invocation.

Issue: #116

PiperOrigin-RevId: 460721541
(cherry picked from commit adc5051)
@androidx androidx locked and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants