The issue described in this question is about cross-forwarding (from http to https or vice versa). Exoplayer supports this, but you must set allowCrossProtocolRedirects
to true
. By default, regular redirects are supported (including 301 redirects). The redirect you receive is most likely a cross-redirect.
To create a data source that you call:
DefaultDataSourceFactory(Context context, String userAgent)
This constructor creates a DefaultHttpDataSourceFactory
that has allowCrossProtocolRedirects
set to false
.
To change this, you need to call:
DefaultDataSourceFactory(Context context, TransferListener<? super DataSource> listener, DataSource.Factory baseDataSourceFactory)
And use your own DefaultHttpDataSourceFactory
with allowCrossProtocolRedirects
set to true
as baseDataSourceFactory
.
For instance:
String userAgent = Util.getUserAgent(context, applicationInfo.getAppName()); // Default parameters, except allowCrossProtocolRedirects is true DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory( userAgent, null /* listener */, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true /* allowCrossProtocolRedirects */ ); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory( context, null /* listener */, httpDataSourceFactory );
If you need to do this more often, you can also create a helper method:
public static DefaultDataSourceFactory createDataSourceFactory(Context context, String userAgent, TransferListener<? super DataSource> listener) {
This will allow cross-forwarding.
Sidenote: β301 Moved Permentlyβ means customers need to update their URL to a new one. "302 Found" is used for regular redirects. If possible, update the URLs that return "301 moved forever."