B4A Library YouTube library

The YouTube library allows you to play YouTube videos inside your application.

It is based on a new service provided by Google. Note that this service is considered experimental.

This library is supported by Android 2.2+. It requires YouTube app v4.2.16 which is currently the latest version. You can update YouTube from Google Play.

SS-2013-01-03_11.57.47.png


Setup instructions
1. Download the native library: https://developers.google.com/youtube/android/player/downloads/
2. Copy libs\YouTubeAndroidPlayerApi.Jar from the zip file to Basic4android libraries folder.
3. Download the attached library, unzip it and copy the files to the libraries folder.
4. Get a developer key. Follow these instructions: https://developers.google.com/youtube/android/player/register
Note that you can leave the SHA1 field empty.

Example code:
B4X:
Sub Process_Globals

End Sub

Sub Globals
   Dim YouTube As YouTubeStandalonePlayer
End Sub

Sub Activity_Create(FirstTime As Boolean)
   YouTube.Initialize("YouTube")
   If YouTube.CheckPlayerSupported <> "SUCCESS" Then
      Msgbox("YouTube service not available: " & CRLF & YouTube.CheckPlayerSupported, "")
   Else
      Activity.AddMenuItem3("Play Video", "PlayVideo", Null, True)
   End If
End Sub
Sub PlayVideo_Click
   YouTube.StartVideo("AIzaSyxxxxxxxx-xxxx-xxxxxxxxxxxx", _
      "0xdZXOM_Otc", 0, False, True)
End Sub

Sub YouTube_Result (Message As String)
   Log("Result = " & Message)
End Sub

Important, YouTube service will not work if the Version Name field is empty.

The player can play in full screen or in lightbox mode. The above screenshot is for lightbox mode.
 

Attachments

  • YouTube.zip
    3.5 KB · Views: 2,493

kozbot

Member
Licensed User
Longtime User
Sure!!!

Thanks Erel... I really appreciate this...
 

Attachments

  • Kozbot.zip
    424.4 KB · Views: 260

kozbot

Member
Licensed User
Longtime User
No problem... This has the same issue... But like I said, I really don't know what I'm doing wrong...

Thanks!
 

Attachments

  • Kozbot.zip
    48.5 KB · Views: 279

kozbot

Member
Licensed User
Longtime User
OMG! Are you serious??? I am SOOOOO sorry for wasting your time!!!

But, thank you for the compliment, and for your help! You're a legend!!!
 

kozbot

Member
Licensed User
Longtime User
hmmm... I changed the variable... and still nothing... It doesn't load anything at all. Doesn't even crash now lol... I just get a blank screen.
 

kozbot

Member
Licensed User
Longtime User
Yeah, I did all that... I got the API key thing... Maybe I should try the other way... Hmmm... Will try again. Thanks again for your help.
 

kozbot

Member
Licensed User
Longtime User
ok... I've set up 3 different API keys... 1 with the SHA1 and 2 without... the SHA1 was an Android key, and then I did an Android 1 and a browser one (just to try) and I'm still just getting a blank screen...

Erel, did you say that it worked for you? the video came up when you compiled? Cos I'm now very lost as to why it's not working for me...
 

kozbot

Member
Licensed User
Longtime User
As I am such a gigantic moron, I didn't realise that you needed to have the title attribute as True for this, but I've made it so that, the title is not necessary and plays on a button click as a lightbox...

Works perfectly!!! Thanks for the help Erel!!!! :)
 

andyr00d

Member
Licensed User
Longtime User
any idea on how to share a video (link) FROM the native youtube app, to my app so it will instead play within my app instead? maybe using an intent?
 

mhartwig

Member
Licensed User
Longtime User
I dont think this lib works any longer. It works on my old 2.3 phone, it does not work on my lollipop phone or bluestacks running lollipop. No errors just nothing ever happens. They both have latest youtube app.
 

Henry Baars

Member
Licensed User
Longtime User
When I try the attached code on my my tablet (acer with android 4.1) "the program has unfortunately stopped"...
YouTube.Initialize("YouTube") seems to work. But when I enable YouTube.CheckPlayerSupported
The app crashes.

-------------------------

(debug dump)
java.lang.NoClassDefFoundError: com.google.android.youtube.player.YouTubeApiServiceUtil
at anywheresoftware.b4a.objects.YouTubeStandalonePlayerWrapper.CheckPlayerSupported(YouTubeStandalonePlayerWrapper.java:36)
at b4a.Scrub.main._activity_create(main.java:302)

---------------------

Acer tablet (512MB) Android 4.1
Youtube app version 11.23.56

Any tips, tricks on how to overcome this problem?
What could cause the crash?

Regards,
Henry
 

Attachments

  • b4avraag.txt
    820 bytes · Views: 219
Last edited:
Top