Android Question Exoplay allowCrossProtocolRedirects(true)

Scantech

Well-Known Member
Licensed User
Longtime User
Any idea how to configure the exoplayer to allowCrossProtocolRedirects(true) in configuration? Thanks
 
Solution
Here:
B4X:
Private Sub CreateUriSource(Uri As String) As Object
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim HttpDataSourceFactory As JavaObject
    HttpDataSourceFactory.InitializeNewInstance("androidx.media3.datasource.DefaultHttpDataSource$Factory", Null)
    HttpDataSourceFactory.RunMethod("setAllowCrossProtocolRedirects", Array(True))
    Dim DataSource As JavaObject = HttpDataSourceFactory.RunMethod("createDataSource", Null)
    Dim DataSourceFactory As JavaObject = ctxt.CreateEvent("androidx.media3.datasource.DataSource.Factory", "", DataSource)
    Dim ProgressiveMediaSourceFactory As JavaObject...

TILogistic

Expert
Licensed User
Longtime User
What library do you use exoplayer2 or exoplayer3?

example exoplayer2
B4X:
        Dim defaultHttpDataSourceFactory As JavaObject
        defaultHttpDataSourceFactory.InitializeNewInstance("com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory", _
            Array(userAgent, Null, connectTimeoutMillis, readTimeoutMillis, allowCrossProtocolRedirects))
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Private Sub CreateUriSource(Uri As String) As Object
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim HttpDataSourceFactory As JavaObject
    HttpDataSourceFactory.InitializeNewInstance("androidx.media3.datasource.DefaultHttpDataSource$Factory", Null)
    HttpDataSourceFactory.RunMethod("setAllowCrossProtocolRedirects", Array(True))
    Dim DataSource As JavaObject = HttpDataSourceFactory.RunMethod("createDataSource", Null)
    Dim DataSourceFactory As JavaObject = ctxt.CreateEvent("androidx.media3.datasource.DataSource.Factory", "", DataSource)
    Dim ProgressiveMediaSourceFactory As JavaObject
    ProgressiveMediaSourceFactory.InitializeNewInstance("androidx.media3.exoplayer.source.ProgressiveMediaSource.Factory", Array(DataSourceFactory))
    Dim MediaItem As JavaObject
    MediaItem.InitializeStatic("androidx.media3.common.MediaItem")
    Return ProgressiveMediaSourceFactory.RunMethod("createMediaSource", Array(MediaItem.RunMethod("fromUri", Array(Uri))))
End Sub

Usage:
B4X:
player1.Prepare(CreateUriSource("https://bestvpn.org/html5demos/assets/dizzy.mp4"))
 
Upvote 0
Solution

Erel

B4X founder
Staff member
Licensed User
Longtime User
What library do you use exoplayer2 or exoplayer3?

example exoplayer2
B4X:
        Dim defaultHttpDataSourceFactory As JavaObject
        defaultHttpDataSourceFactory.InitializeNewInstance("com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory", _
            Array(userAgent, Null, connectTimeoutMillis, readTimeoutMillis, allowCrossProtocolRedirects))
This code will not do anything.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Here:
B4X:
Private Sub CreateUriSource(Uri As String) As Object
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim HttpDataSourceFactory As JavaObject
    HttpDataSourceFactory.InitializeNewInstance("androidx.media3.datasource.DefaultHttpDataSource$Factory", Null)
    HttpDataSourceFactory.RunMethod("setAllowCrossProtocolRedirects", Array(True))
    Dim DataSource As JavaObject = HttpDataSourceFactory.RunMethod("createDataSource", Null)
    Dim DataSourceFactory As JavaObject = ctxt.CreateEvent("androidx.media3.datasource.DataSource.Factory", "", DataSource)
    Dim ProgressiveMediaSourceFactory As JavaObject
    ProgressiveMediaSourceFactory.InitializeNewInstance("androidx.media3.exoplayer.source.ProgressiveMediaSource.Factory", Array(DataSourceFactory))
    Dim MediaItem As JavaObject
    MediaItem.InitializeStatic("androidx.media3.common.MediaItem")
    Return ProgressiveMediaSourceFactory.RunMethod("createMediaSource", Array(MediaItem.RunMethod("fromUri", Array(Uri))))
End Sub

Usage:
B4X:
player1.Prepare(CreateUriSource("https://bestvpn.org/html5demos/assets/dizzy.mp4"))
Awesome Erel!!! works like a charm.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Here:
B4X:
Private Sub CreateUriSource(Uri As String) As Object
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim HttpDataSourceFactory As JavaObject
    HttpDataSourceFactory.InitializeNewInstance("androidx.media3.datasource.DefaultHttpDataSource$Factory", Null)
    HttpDataSourceFactory.RunMethod("setAllowCrossProtocolRedirects", Array(True))
    Dim DataSource As JavaObject = HttpDataSourceFactory.RunMethod("createDataSource", Null)
    Dim DataSourceFactory As JavaObject = ctxt.CreateEvent("androidx.media3.datasource.DataSource.Factory", "", DataSource)
    Dim ProgressiveMediaSourceFactory As JavaObject
    ProgressiveMediaSourceFactory.InitializeNewInstance("androidx.media3.exoplayer.source.ProgressiveMediaSource.Factory", Array(DataSourceFactory))
    Dim MediaItem As JavaObject
    MediaItem.InitializeStatic("androidx.media3.common.MediaItem")
    Return ProgressiveMediaSourceFactory.RunMethod("createMediaSource", Array(MediaItem.RunMethod("fromUri", Array(Uri))))
End Sub

Usage:
B4X:
player1.Prepare(CreateUriSource("https://bestvpn.org/html5demos/assets/dizzy.mp4"))
Is it a complement to this or could this method be added?
Because I see that the source properties are being changed.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Here:
B4X:
Private Sub CreateUriSource(Uri As String) As Object
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim HttpDataSourceFactory As JavaObject
    HttpDataSourceFactory.InitializeNewInstance("androidx.media3.datasource.DefaultHttpDataSource$Factory", Null)
    HttpDataSourceFactory.RunMethod("setAllowCrossProtocolRedirects", Array(True))
    Dim DataSource As JavaObject = HttpDataSourceFactory.RunMethod("createDataSource", Null)
    Dim DataSourceFactory As JavaObject = ctxt.CreateEvent("androidx.media3.datasource.DataSource.Factory", "", DataSource)
    Dim ProgressiveMediaSourceFactory As JavaObject
    ProgressiveMediaSourceFactory.InitializeNewInstance("androidx.media3.exoplayer.source.ProgressiveMediaSource.Factory", Array(DataSourceFactory))
    Dim MediaItem As JavaObject
    MediaItem.InitializeStatic("androidx.media3.common.MediaItem")
    Return ProgressiveMediaSourceFactory.RunMethod("createMediaSource", Array(MediaItem.RunMethod("fromUri", Array(Uri))))
End Sub

Usage:
B4X:
player1.Prepare(CreateUriSource("https://bestvpn.org/html5demos/assets/dizzy.mp4"))
Isn't the mime type set in datasource (HLS)?
"application/x-mpegURL"
see:
1714529605466.png
 
Upvote 0
Top