DarkWolfalpha
Member
B4X:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private SimpleExoPlayerView1 As SimpleExoPlayerView
Private player1 As SimpleExoPlayer
End Sub
Public Sub Initialize
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
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
player1.Initialize("player")
Dim sources As List
sources.Initialize
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)))
player1.Prepare(player1.CreateListSource(sources))
SimpleExoPlayerView1.Player = player1
player1.Play
End Sub
Sub Player_Ready
Log("Ready")
End Sub
Sub Player_Error (Message As String)
Log("Error: " & Message)
End Sub
Sub Player_Complete
Log("complete")
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
I needs Exoplayer and subtitle but I get this error :
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
b4xmainpage_createsinglesamplemediasource (java line: 183)
java.lang.RuntimeException: Constructor not found.
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:94)
at b4a.example.b4xmainpage._createsinglesamplemediasource(b4xmainpage.java:183)
at b4a.example.b4xmainpage$ResumableSub_B4XPage_Created.resume(b4xmainpage.java:115)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Please help me I am new in this field ...