Android Question MXPlayer Subtitle API Intent

ronovar

Active Member
Licensed User
Longtime User
I have following code to start mxplayer from b4a apk and it plays video successfully...now i would like to add external srt file from http to be automatically included when video is played..so i get this api:

https://sites.google.com/site/mxvpen/api

Source code example in java is here:

https://sites.google.com/site/mxvpen/api/sample_code.zip?attredirects=0&d=1

My code to start mxplayer with video that works:

VideoClub.MovieURL = "http://192.168.1.100/NAME.AVI"
VideoClub.MovieSubtitle = "http://192.168.1.100/NAME.SRT"

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    'DEFINE - sw
    Dim sw As Byte = 2
    'DEFINE - Subtitle
    Dim Subtitle(0) As String = Array As String(VideoClub.MovieSubtitle)
    'DEFINE - Intent
    Dim Intent1 As Intent
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    'INITIALIZE - Movie
    Intent1.Initialize(Intent1.ACTION_VIEW, VideoClub.MovieURL)
    'SET - Title
    Intent1.PutExtra("title", VideoClub.MovieTitle)
    'SET - Data Type
    Intent1.SetType("application/x-mpegURL")
    'SET - S/W Decoder
    Intent1.PutExtra("decode_mode", sw)
    'SET - MX Player
    Intent1.SetComponent("com.mxtech.videoplayer.pro")

    'START - MX Player
    StartActivityForResult(Intent1)
End Sub

Using example in mxplayer api i try to add this way:

B4X:
'SET - Subtitle
    Intent1.PutExtra("subs", Subtitle)
    Intent1.PutExtra("subs.name", "NAME")
    Intent1.PutExtra("subs.filename", "NAME.SRT")
    Intent1.PutExtra("subs.enable", Subtitle)

MXPlayer is started, video is played but not SRT loaded in MXPlayer..so how it needs to be done correctly using example from java?

Thanks.
 

ronovar

Active Member
Licensed User
Longtime User
I im using MXPlayer because it have all codecs inside (audio and video), it is based on ffmpeg compiled files for android cpu, and it have support for all kind of subtitles so i don't need to write my own srt reader using timers and compare start and end time and read next line from srt file. This is the reason why i im using external MXPlayer.

Here i im attaching code TestActivity.java that have defined how to run, i run using this example in android studio and it reads file from url and local file and automatically is displayed on video so how to implement this in B4A?

I try using:

subs posted above and array but nothing show up in B4A, on android studio using java code it works very well..so i im missing some point to send to mxplayer using intent1 wrong?
 

Attachments

  • TestActivity.java
    20.6 KB · Views: 290
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Here is the code that works very well...but i first download srt file to /storage/emulated/0/Subtitle and then i send using Intend to MXPlayer to read that SRT file...this works great...but i need to read from http url srt...so i send url using Intent to MXPlayer and then subitle does not shown.

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    'DEFINE - ion
    Private ion As Object
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    'DEFINE - hw
    Dim HW As Byte = 1
    'DEFINE - sw
    Dim SW As Byte = 2
    'DEFINE - decoder
    Dim Decoder As Byte = SW
    'DEFINE - Subtitle
    Dim Subtitle(0) As String = Array As String(VideoClub.MovieSubtitle)
    'DEFINE - Intent
    Dim Intent1 As Intent
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    'INITIALIZE - Movie
    Intent1.Initialize(Intent1.ACTION_VIEW, VideoClub.MovieURL)
    'CHECK - Trailer
    If (VideoClub.MovieURL.Contains("trailer") = True) Then
        'SET - Decoder
        Decoder = HW
        
        'SET - Subtitle
        Intent1.PutExtra("subs", Subtitle)
        Intent1.PutExtra("subs.name", "Croatian")
        Intent1.PutExtra("subs.filename", "NAME.SRT")
        Intent1.PutExtra("subs.enable", Subtitle)
    End If
    'SET - Title
    Intent1.PutExtra("title", VideoClub.MovieTitle)
    'SET - Data Type
    Intent1.SetType("application/x-mpegURL")
    'SET - S/W Decoder
    Intent1.PutExtra("decode_mode", Decoder)
    'SET - MX Player
    Intent1.SetComponent("com.mxtech.videoplayer.pro")
    'START - MX Player
    StartActivityForResult(Intent1)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
End Sub

Sub ion_Event (MethodName As String, Args() As Object) As Object
    'CHECK - Exit Player
    If (Args(0) = 0) Then
        'EXIT - Player
        Activity.Finish
    End If
    'RETURN - False
    Return False
End Sub

Sub StartActivityForResult(i As Intent)
    'INITIALIZE - JavaObject
    Dim jo As JavaObject = GetBA
    'CREATE - Event
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    'RUN - Method
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
    'DEFINE - JavaObject
    Dim jo As JavaObject
    'DEFINE - cls
    Dim cls As String = Me
    'GEt - Name
    cls = cls.SubString("class ".Length)
    'INITIALIZE - cls
    jo.InitializeStatic(cls)
    'RETURN - ProcessBA
    Return jo.GetField("processBA")
End Sub
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Yes you are right Erel, but looking at the source code and running again example with my links with http url for srt works in android studio, but with intent does not work. Please look a the aabove attached TestActivity.java it have defined three ways of getting subtitle:

B4X:
Subtitle subtitle0_0 = new Subtitle("https://s3.amazonaws.com/mediatest888/s1.smi");
        subtitle0_0.name = "SAMI subtitle";
        subtitle0_0.filename = "a.smi";
        
        Subtitle subtitle0_1 = new Subtitle("file:///storage/emulated/0/Movies/a.srt");
        Subtitle subtitle0_2 = new Subtitle("http://192.168.0.102/Videos/vobsub/VTS_01_0.idx");
        subtitle0_2.name = "VobSub";
        
        Subtitle subtitle0_3 = new Subtitle("http://192.168.0.102/Videos/a.srt");

- getting from S3 amazonaws.com
- getting from local file
- getting from http server

So i im sure that i send wrong parameters using intent to mxplayer when i send url...so if you could please check this in b4a using example java code what parameters i need to send to be read directly from url.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
It is ok..i will not invest more time on this...i leave it as it...i just put in B4A to download srt file and save it in internal storage and then when SRT is saved successfully into android internal storage i start mxplayer sending using Intent to read internal storage SRT file...this works very well.

Thanks Erel for help.
 
Upvote 0
Top