Sub Process_Globals
Dim player_exo As SimpleExoPlayer
End Sub
Sub Globals
Private ExoPlayerView As SimpleExoPlayerView
Dim btnClose As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
If(FirstTime) Then
player_exo.Initialize("Player")
player_exo.Prepare(player_exo.CreateFileSource("/storage/0403-0201/Android/data/baz.movie.player/files","ShogSubs.mkv"))
End If
Activity.LoadLayout("EXOmain")
ExoPlayerView.Player=player_exo
End Sub
Sub Player_TrackChanged
End Sub
Sub Player_Ready
Log("Player is ready")
Dim jo As JavaObject = player_exo
Dim TrackGroups As JavaObject = jo.GetFieldJO("player").RunMethod("getCurrentTrackGroups", Null)
For i = 0 To TrackGroups.GetField("length") - 1
Dim TrackGroup As JavaObject = TrackGroups.RunMethod("get", Array(i))
For j = 0 To TrackGroup.GetField("length") - 1
Dim Format As JavaObject = TrackGroup.RunMethodJO("getFormat", Array(j))
Log("=======Sample MIME Type: " & Format.GetField("sampleMimeType") & " =========")
Log("Codecs: " & Format.GetField("codecs"))
Log("Bitrate: " & Format.GetField("bitrate"))
Log("Width: " & Format.GetField("width"))
Log("Height: " & Format.GetField("height"))
Log("Frame Rate: " & Format.GetField("frameRate"))
Log("Channel Count: " & Format.GetField("channelCount"))
Log("Sample Rate: " & Format.GetField("sampleRate"))
Log("Selection Flags: " & Format.GetField("selectionFlags"))
Log("Language: " & Format.GetField("language"))
Log("Label: " & Format.GetField("label"))
Log("Role Flags: " & Format.GetField("roleFlags"))
Log("Average Bitrate: " & Format.GetField("averageBitrate"))
Log("Peak Bitrate: " & Format.GetField("peakBitrate"))
Next
Next
SetPreferredAudioLanguage("en")
Subtitles_OFF(False)
SetPreferredTextLanguage("th")
Dim ForegroundColor As Int = 0xFFFFFF00
Dim BackgroundColor As Int = 0x00000000
Dim WindowColor As Int = 0x30000000
SubtitleStyle(12,2,ForegroundColor,BackgroundColor,WindowColor)
End Sub
Sub SubtitleStyle(TextSize As Int, Fraction As Int, ForegroundColor As Int, BackgroundColor As Int, WindowColor As Int)
Try
Dim SubtitleView As JavaObject = ExoPlayerView
SubtitleView = SubtitleView.RunMethod("getSubtitleView", Null)
If SubtitleView <> Null And SubtitleView.IsInitialized Then
Dim TextSize2 As Float = TextSize
SubtitleView.RunMethod("setFixedTextSize", Array(2, TextSize2))
Dim fraction2 As Float = 0.01 * Fraction
SubtitleView.RunMethod("setBottomPaddingFraction", Array(fraction2))
Dim CaptionStyleCompat As JavaObject
CaptionStyleCompat.InitializeNewInstance("androidx.media3.ui.CaptionStyleCompat", Array (ForegroundColor, BackgroundColor, WindowColor, 0,0, Typeface.MONOSPACE))
SubtitleView.RunMethod("setStyle", Array(CaptionStyleCompat))
Log("Subtitle customization applied")
Else
Log("SubtitleView not found")
End If
Catch
Log(LastException.Message)
End Try
End Sub
Private Sub SetPreferredTextLanguage(Language As String)
Dim jo As JavaObject = player_exo
Dim TrackSelector As JavaObject = jo.GetField("trackSelector")
TrackSelector.RunMethod("setParameters", Array( _
TrackSelector.RunMethodJO("buildUponParameters", Null) _
.RunMethod("setPreferredTextLanguage", Array(Language))))
End Sub
Private Sub Subtitles_OFF(myvalue As Boolean)
Dim jo As JavaObject = player_exo
Log("enter disable")
Dim trackSelector As JavaObject = jo.GetField("trackSelector")
Dim parametersBuilder As JavaObject = trackSelector.RunMethodJO("buildUponParameters", Null)
Dim trackGroups As JavaObject = jo.GetFieldJO("player").RunMethod("getCurrentTrackGroups", Null)
For i = 0 To trackGroups.GetField("length") - 1
Dim trackGroup As JavaObject = trackGroups.RunMethod("get", Array(i))
For j = 0 To trackGroup.GetField("length") - 1
Dim format As JavaObject = trackGroup.RunMethodJO("getFormat", Array(j))
Dim mime As String = format.GetField("sampleMimeType")
If mime.contains("x-subrip") Then
parametersBuilder.RunMethodJO("setRendererDisabled", Array(i, myvalue))
End If
Next
Next
trackSelector.RunMethod("setParameters", Array(parametersBuilder.RunMethod("build", Null)))
End Sub
Sub SelectSubtitleTrack(preferredSubtitleLanguage As String)
Dim jo As JavaObject = player_exo
Dim trackSelector As JavaObject = jo.GetField("trackSelector")
Dim TrackGroups As JavaObject = jo.GetFieldJO("player").RunMethod("getCurrentTrackGroups", Null)
Dim builder As JavaObject = trackSelector.RunMethodJO("buildUponParameters", Null)
For i = 0 To TrackGroups.GetField("length") - 1
Dim TrackGroup As JavaObject = TrackGroups.RunMethod("get", Array(i))
For j = 0 To TrackGroup.GetField("length") - 1
Dim Format As JavaObject = TrackGroup.RunMethodJO("getFormat", Array(j))
Dim mime As String = Format.GetField("sampleMimeType")
Dim language As String = Format.GetField("language")
Log("Track " & i & "-" & j & " MIME type: " & mime & ", Language: " & language)
If mime.Contains("x-subrip") And language = preferredSubtitleLanguage Then
Log("Found preferred subtitle track at " & i & "-" & j)
Dim indices() As Int = Array As Int(j)
Dim selectionOverride As JavaObject
selectionOverride.InitializeNewInstance("androidx.media3.exoplayer.trackselection.DefaultTrackSelector$SelectionOverride", Array(i, indices))
Dim trackSelections As JavaObject = builder.RunMethodJO("setRendererDisabled", Array(2, False))
trackSelections.RunMethod("setSelectionOverride", Array(i, TrackGroup, selectionOverride))
trackSelector.RunMethod("setParameters", Array(builder.RunMethod("build", Null)))
Log("Selected subtitle track: " & language)
Return
End If
Next
Next
Log("No preferred subtitle track found.")
End Sub
Private Sub SetPreferredAudioLanguage(Language As String)
Dim jo As JavaObject = player_exo
Dim TrackSelector As JavaObject = jo.GetField("trackSelector")
TrackSelector.RunMethod("setParameters", Array( _
TrackSelector.RunMethodJO("buildUponParameters", Null) _
.RunMethod("setPreferredAudioLanguage", Array(Language))))
End Sub
Private Sub btnClose_Click
Activity.Finish
ExitApplication
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub