#Region Project Attributes
#ApplicationLabel: DSH YOUTUBE PLAYER
#FullScreen: True
#IncludeTitle: False
#VersionCode: 1
#VersionName: 1.0
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim Job1 As HttpJob
Dim Job2 As HttpJob
Dim SourceText1 As String
Dim Timer1 As Timer
Dim YouDown1 As String
Dim YouLink1 As String
End Sub
Sub Globals
Dim VV1 As VideoView
Dim LayoutVal As LayoutValues
End Sub
Sub Activity_Create(FirstTime As Boolean)
VV1.Initialize("VV1")
Activity.AddView(VV1,0,0,100%x,100%y)
Timer1.Initialize("Timer1",100)
Timer1.Enabled = False
LayoutVal = GetDeviceLayoutValues
YouDown1 = "https://www.youtube.com/watch?v=cgxWP4Wu77s"
YouDown1 = "https://www.saveitoffline.com/process/?url=" & YouDown1 & "&type=xml"
Job1.Initialize("Job1", Me)
Job1.Download(YouDown1)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub JobDone(job As HttpJob)
Dim n, m As Long
If job.Success = True Then
Select job.JobName
Case "Job1" 'Get Link for 360p video
SourceText1 = Job1.GetString
n=SourceText1.indexof("<label>360p - mp4")
If n=-1 Then Return
n=SourceText1.indexof2("<url>",n+15)
If n=-1 Then Return
n=n+5
m=SourceText1.indexof2("</url>",n+5)
If m=-1 Or m<n Then Return
YouLink1 = SourceText1.SubString2(n,m)
Job2.Initialize("Job2", Me)
Job2.Download(YouLink1)
Case "Job2" 'Download MP4
Dim out As OutputStream
If File.Exists(File.DirRootExternal,"youvideo1.mp4") Then File.Delete(File.DirRootExternal,"youvideo1.mp4")
out = File.OpenOutput(File.DirRootExternal,"youvideo1.mp4",False )
File.Copy2(job.GetInputStream, out)
out.Close 'Directly starting to play the MP4 outputstream in stead of downloading it might be possible??
Timer1.enabled = True
VV1.LoadVideo(File.DirRootExternal,"youvideo1.mp4")
VV1.Play
End Select
job.Release
Else
Log(job.ErrorMessage)
End If
End Sub
Sub Timer1_tick 'Used to center VV1, depending on the actual video width!
Dim VV1width1 As Long
Dim VV1height1 As Long
If VV1.IsPlaying = False Then Return
If VV1.Position > 800 Then
Timer1.Enabled = False
Return
End If
Dim jo As JavaObject= VV1
Dim vvwidth As String = jo.RunMethodJO("getMeasuredWidth", Null)
Dim vvheight As String = jo.RunMethodJO("getMeasuredHeight", Null)
VV1width1 = vvwidth.Replace("(Integer) ","")
VV1height1 = vvheight.Replace("(Integer) ","")
Log(VV1width1 & " x " & VV1height1)
VV1.Left = (LayoutVal.Width - VV1width1)/2
End Sub