Android Question ExoPlayer subtitles

Discussion in 'Android Questions' started by MAGAREY, Jun 1, 2018.

  1. MAGAREY

    MAGAREY Member Licensed User

    its posible to load srt in exoplayer, i think in the lib is missing that part.
    any advice?
    thanks in advance
     
    KZero likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Probably possible with JavaObject. Can you upload the subtitles file or source?
     
    KZero likes this.
  3. MAGAREY

    MAGAREY Member Licensed User

    Last edited: Jun 3, 2018
  4. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]


    1. Download the subtitles and save them as UTF8 file:
    Code:
    Dim j As HttpJob
       j.Initialize(
    "", Me)
       j.Download(
    "http://45.79.158.247/test.srt")
       
    Wait For (j) JobDone(j As HttpJob)
       
    If j.Success Then
           
    Dim s As String = j.GetString2("windows-1252")
           
    File.WriteString(File.DirInternal, "1.srt", s)
       
    End If
       j.Release
    2. Created a merged source with the video source and subtitles source:
    Code:
    Dim subtitles As Object = CreateSingleSampleMediaSource("file://" & File.Combine(File.DirInternal, "1.srt"))
    Dim video As Object = player1.CreateUriSource("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
    sources.Add(CreateMergedSource(
    Array(video, subtitles)))
    Subs:
    Code:
    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 StringAs 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
    Depends on ContentResolver library.
     
    Sasuke Sama, KZero, MAGAREY and 4 others like this.
  5. MAGAREY

    MAGAREY Member Licensed User

    Thanks Erel!!, it's worked.
     
  6. MAGAREY

    MAGAREY Member Licensed User

    hi, erel, me again, its possible to change the font or the text size?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Changing the subtitles style and text size:
    Code:
    Dim SubtitleView As JavaObject = SimpleExoPlayerView1
    SubtitleView = SubtitleView.RunMethod(
    "getSubtitleView"Null)
    Dim TextSize As Float = 20
    SubtitleView.RunMethod(
    "setFixedTextSize"Array(2, TextSize))
    Dim CaptionStyleCompat As JavaObject
    Dim ForegroundColor As Int = Colors.Red
    Dim BackgroundColor As Int = Colors.Yellow
    Dim WindowColor As Int = Colors.White
    CaptionStyleCompat.InitializeNewInstance(
    "com.google.android.exoplayer2.text.CaptionStyleCompat"Array ( _
       ForegroundColor, BackgroundColor, WindowColor, 
    00Typeface.MONOSPACE))
    SubtitleView.RunMethod(
    "setStyle"Array(CaptionStyleCompat))
     
    asales, MAGAREY, inakigarm and 2 others like this.
  8. Sasuke Sama

    Sasuke Sama Active Member Licensed User

    hi i know this old but can somebody tell me what the sources is?
    when i copy the code above im getting error with this line
    Code:
    sources.Add(CreateMergedSource(Array(video, subtitles)))
    undecleard var "sources"
     
  9. DonManfred

    DonManfred Expert Licensed User

    See Post #4 for an example.

    Away from that: Create a new thread and post all relevant infos to get help.
     
  10. Sasuke Sama

    Sasuke Sama Active Member Licensed User

    I tried the example above and copied it to my project but as i said im only having a problem with this line
     
  11. DonManfred

    DonManfred Expert Licensed User

  12. Sasuke Sama

    Sasuke Sama Active Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice