how to Resume the Video when the user unlocks the sreen

shashkiranr

Active Member
Licensed User
Longtime User
Hi,

I have an application where the video is played using videoview.

Consider the Scenario where the user locks the phone when the video is playing. when the user unlocks the phone, the video should resume from where it stopped. How to achieve this?

Kindly plz suggest.:sign0163:
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi Margret,

The Video playing is from Youtube, So when the video is streaming and the phone locks, the streaming should continue . when the user again unlocks the phone the video should play from the where it stopped.

i tried your suggested approach and it did not work,

I have pasted the code below, kindly give ur suggestions, thank u :)

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim actname As String
Dim index As Int
Dim url As String
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.
Dim vv As VideoView
Dim p As Phone
Dim tt As Timer : tt.Initialize("tt", 250)
Dim videopositon As Int
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("Videoplay")
vv.Initialize("VV")
loadtheVideo
End Sub

Sub loadtheVideo
Activity.Title = actname&" Subhashita "&index
p.SetScreenOrientation(0)
Activity.AddView(vv, 0, 0, 100%x, 100%y)
Log(url)
vv.LoadVideo("http",url)
vv.Play
ProgressDialogShow("Please wait...")
tt.Enabled = True
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub tt_Tick
If vv.IsPlaying = True Then
ProgressDialogHide
tt.Enabled = False
End If
End Sub

Sub VV_Complete
vv.Stop
Log("Video Completed")

End Sub
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
I didn't test any of this, but look at the changes and you will see an idea of what I was saying.

B4X:
'Activity module
Sub Process_Globals
   Dim actname As String
   Dim index As Int
   Dim url As String
   Dim videoposition = 0 As Int
End Sub
Sub Globals
   Dim vv As VideoView
   Dim p As Phone
   Dim tt As Timer : tt.Initialize("tt", 250)
End Sub
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Videoplay")
   vv.Initialize("VV")
   loadtheVideo
End Sub
Sub loadtheVideo 
   Activity.Title = actname & " Subhashita " & index
   p.SetScreenOrientation(0)
   Activity.AddView(vv, 0, 0, 100%x, 100%y)
   Log(url)
   vv.LoadVideo("http", url)
   vv.Play
   If videoposition > 0 Then vv.Position = videoposition
   ProgressDialogShow("Please wait...")
   tt.Enabled = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
   videoposition = vv.Position
End Sub
Sub tt_Tick 
   If vv.IsPlaying = True Then
      ProgressDialogHide
   End If
End Sub
Sub VV_Complete 
   vv.Stop
   tt.Enabled = False
   videoposition = 0
   Log("Video Completed")
End Sub
 
Upvote 0
Top