Android Question Advise - Best way to stop...

jmoeller

Member
Licensed User
Longtime User
I need help with a simple app I am writing, I need to play a youtube video (have got that working) but only for a set period of time. What is the best way to accomplish this...


Main Module (leaving the basics out)

Activity.LoadLayout("MainScreen")

YouTube.StartVideo("AI?X?X?X?X?X??X?X?X?X??X?X?X", _
Main.VidID, Main.tStart*1000, True, True)

The above code plays the video (VidID) and starts at tStart. All is working there. However, the YouTube functionality doesn't appear to have a stop, so I need it to stop at tEnd (say 10 seconds).

What is the best way to accomplish this? I suspect I need a timer to tEnd that will kill the YouTube. Please provide code (not just overview) as I am not too familiar with B4A.

Thanks
Jonathan
 

jmoeller

Member
Licensed User
Longtime User
I have created the sub in the Starter. But I am having trouble finding the right syntax to call it.

 
Upvote 0

jmoeller

Member
Licensed User
Longtime User
Sorry, still struggling. I took out all of the unnecessary code and have attached a simple app that should play a Youtube video for a few seconds in the background and stop. But I still don't have the code right. NOTE: I am using B4A 5.8.

Thanks.
 

Attachments

  • ServerTest.zip
    9.9 KB · Views: 213
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should never use code like this:
B4X:
Sub Wait(Seconds As Int)
   Dim Ti As Long
   Ti = DateTime.Now + (Seconds * 1000)
   Do While DateTime.Now < Ti
      DoEvents
   Loop
End Sub
Don't use DoEvents at all.

The code I posted uses Sleep. Sleep is not similar to the Wait code you implemented. It doesn't hold the main thread (watch the resumable subs video tutorial for more information). You will need to replace it with a timer.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…