#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#BridgeLogger: True
#AdditionalRes: D:\B4A\JWS2024\res
#AdditionalJar: com.android.support:support-v4
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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.
Private ScrollView_slide As ScrollView
Private Panel_slide As Panel
Dim cs As CSBuilder
Private PanelStream As Panel
Dim yt As YouTubePlayerView
Dim Link_Yotube As String
Private ButtonCheck As Button
Private EditTextURL As EditText
Private ButtonSend As Button
Private EditTextID As EditText
Dim yt_Tutor As YouTubePlayerView
Dim Link_Tutor = "qIRYMWLeVC0" As String
Dim Click As Boolean
Private PanelTutorial As Panel
Private Panel3 As Panel
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("scroll_stream")
ScrollView_slide.Panel.LoadLayout("Stream")
ScrollView_slide.panel.Height = Panel_slide.Height
Activity.Title = cs.Initialize.Color(Colors.White).Append("Yotube Streaming").PopAll
yt.Initialize("yt")
yt_Tutor.Initialize("yt_Tutor")
PanelStream.AddView(yt,0,0,100%x,50%y)
Panel3.AddView(yt_Tutor,0,0,100%x,50%y)
If File.Exists(File.DirInternal, "Link.txt") Then
Link_Yotube = File.ReadString(File.DirInternal, "Link.txt")
EditTextID.Text = Link_Yotube
Else
Link_Yotube = "qIRYMWLeVC0"
End If
End Sub
Sub LoadYoutube(Link As String)
yt.loadVideo(Link, 0) '4YwNW8OlvqU
yt.playVideo
End Sub
Sub LoadYoutube1(Link As String)
yt_Tutor.loadVideo(Link, 0) '4YwNW8OlvqU
yt_Tutor.playVideo
End Sub
Sub yt_ready
Log("Youtube view is ready")
LoadYoutube(Link_Yotube)
End Sub
Sub yt_enterfullscreen
Log("FullScreen")
' yt.loadVideo("UnmznFua_9s", 0)
' yt.playVideo
End Sub
Sub yt_exitfullscreen
Log("ExitFullScreen")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
yt.release
End Sub
Private Sub ButtonCheck_Click
Log(EditTextURL.Text)
If EditTextURL.Text.Length > 0 Then
Test(EditTextURL.Text)
End If
End Sub
Private Sub EditTextURL_TextChanged (Old As String, New As String)
End Sub
Private Sub ButtonSend_Click
If EditTextID.Text.Length > 0 Then
' CallSub2(Starter, "SendMessage", "Youtube URL" & "#" & EditTextID.Text & "#")
File.WriteString(File.DirInternal, "Link.txt", EditTextID.Text)
End If
End Sub
Private Sub EditTextID_TextChanged (Old As String, New As String)
If EditTextID.Text.Length > 0 Then
LoadYoutube(EditTextID.Text)
End If
End Sub
Sub Test(URL As String)
Log("URL : " & URL)
Dim m As Map = ExtractURLStruct(URL)
' For Each Key As String In m.Keys
' Log( "Key: " & Key & " : " & m.Get(Key))
' Next
' Log(" ----- Path ----- ")
For Each Value As String In Regex.Split("/", m.Get("path"))
If Value.Length = 0 Then Continue
Log("Value: " & Value)
EditTextID.Text = Value
Next
End Sub
Public Sub ExtractURLStruct(URL As String) As Map
Dim Pattern As String = $"^([^:\/?#]+):\/\/([^\/:]+)(?::(\d+))?(\/[^?#]*)?(?:\?([^#]*))?(?:#(.*))?"$
Dim Matcher As Matcher = Regex.Matcher(Pattern, URL)
Dim Result As Map : Result.Initialize
If Matcher.Find Then
Result.Put("url", Matcher.Group(0))
Result.Put("scheme", Matcher.Group(1))
Result.Put("domain", Matcher.Group(2))
Result.Put("port", Matcher.Group(3))
Result.Put("path", Matcher.Group(4))
Result.Put("parameters",Matcher.Group(5))
Result.Put("anchor", Matcher.Group(6))
End If
Return Result
End Sub
Private Sub Button_back_Click
Activity.Finish
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
Activity.Finish
End If
Return False
End Sub
Private Sub LabelIconYoutube_Click
Click = Click <> True
If Click Then
PanelTutorial.Visible = True
LoadYoutube1(Link_Tutor)
Else
yt_Tutor.pauseVideo
PanelTutorial.Visible = False
End If
End Sub
Private Sub LabelTutorial_Click
Click = Click <> True
If Click Then
PanelTutorial.Visible = True
LoadYoutube1(Link_Tutor)
Else
yt_Tutor.pauseVideo
PanelTutorial.Visible = False
End If
End Sub