Android Question Exoplayer subtitle issue

ncgege

Member
Licensed User
Hi,Erel I've saw one example you wrote on our form,https://www.b4x.com/android/forum/threads/exoplayer-subtitles.93712/
and I did like these codes ,just change the srt file and video to mine ,the playerview works but don't show the subtitle. can you have a look at these codes,thank you.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim j As HttpJob
    Dim sources As List
    sources.Initialize
    j.Initialize("", Me)
    j.Download("http://221.10.137.60:8000/download/mp4/Queen_Gorgo_Address_the_Spartan_Apella.srt")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim s As String = j.GetString2("windows-1252")
        File.WriteString(File.DirInternal, "Queen_Gorgo_Address_the_Spartan_Apella.srt", s)
    End If
    j.Release
    Dim subtitles As Object = CreateSingleSampleMediaSource("file://" & File.Combine(File.DirInternal, "Queen_Gorgo_Address_the_Spartan_Apella.srt"))
    Log(("file://" & File.Combine(File.DirInternal, "Queen_Gorgo_Address_the_Spartan_Apella.srt")))
    Dim video As Object = player1.CreateUriSource("http://221.10.137.60:8000/download/mp4/Queen_Gorgo_Address_the_Spartan_Apella.mp4")
    sources.Add(CreateMergedSource(Array(video, subtitles)))
    If FirstTime Then
        player1.Initialize("player")
        Dim sources As List
        sources.Initialize
        sources.Add(player1.CreateUriSource("http://221.10.137.60:8000/download/mp4/Queen_Gorgo_Address_the_Spartan_Apella.mp4"))
        player1.Prepare(player1.CreateListSource(sources))
       
    End If
    Activity.LoadLayout("1")
    SimpleExoPlayerView1.Player = player1
    player1.Play
End Sub

Sub CreateMergedSource(Sources() As Object) As Object
    Dim arr As JavaObject
    arr.InitializeArray("com.google.android.exoplayer2.source.MediaSource", Sources)
    Dim m As JavaObject
    Return m.InitializeNewInstance("com.google.android.exoplayer2.source.MergingMediaSource", Array(arr))
End Sub

Sub CreateSingleSampleMediaSource (Uri As String) As Object
    Dim format As JavaObject
    format = format.InitializeStatic("com.google.android.exoplayer2.Format").RunMethod("createTextSampleFormat", Array(Null, "application/x-subrip", 1, "en"))
    Dim source As JavaObject
    Dim u As Uri
    u.Parse(Uri)
    Dim exo As JavaObject = player1
    source.InitializeNewInstance("com.google.android.exoplayer2.source.SingleSampleMediaSource", Array(u, exo.RunMethod("createDefaultDataFactory", Null), _
       format, -9223372036854775807))
    Return source
End Sub
 
Top