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,586

Henry Baars

Member
Licensed User
Longtime User
Hello Erel, thanks for your reply.

Yes, the google play services is running. (9.2.65) (with latest update in place as far as I can tell)
Maybe also worth mentioning. This is not my first android app. I have several other apps up and running. So the b4a combination with the acer tablet is working.
But I have been away from the keyboard for over a year now. Right now I am re-learning B4A again. So it is possible I overlooked something totally stupid.
But when I reinstall my other apps I created more then a year ago, they all install and work without any problems. This tells me the B4A environment (and libraries) have not changed that much over the last year. (I think)
 

Attachments

  • full error message.txt
    1.2 KB · Views: 297

Henry Baars

Member
Licensed User
Longtime User
Obviously not the right one...
Upgraded to 6.0.
Installing and running are ok now. (I had at least the Video ID and de API key things right. The youtube connection to a hidden link worked on the first run :)

So,... something totally stupid after all.
I totally forgot that B4A upgrades are not automatic. (I think?)
Anyways, thank you so much for pointing me in the right direction.
 

rafaelbr20

Member
Licensed User
Longtime User
Hi ! There is no Close Button on Lightbox and FullScreen mode ! How user closes the video ?

And when i open in Full Screen mode, and press return button, my screen gets white !
 

rafaelbr20

Member
Licensed User
Longtime User
The user can click on the back key.
Erel, thanks for reply ! But when back key is clicked, does not return to my activity and the screen gets white .... do i have do load all activity objects again on "Resume" sub ?
 

Douglas Farias

Expert
Licensed User
Longtime User
Hi all.
with this lib its possible get the YouTube_Result when the video its completed?
on the example code the video finish and the lightbox or fullscreen still opened, the YouTube_Result is called only when the user press backkey.
its possible detect when the video finish (complete) and call YouTube_Result or simulate a backkey press when video finish?

thx
 

victormedranop

Well-Known Member
Licensed User
Longtime User
I am working with this amazing library, but i want integrate this with a sinage software that i developed.
how can i close the you tube session without interact with the screen?

any one with the same issue?

Victor
 

Beja

Expert
Licensed User
Longtime User
Hi Erel,
In the create a new key.. I found it one must upload (create) a project first in order to get a key.. but the project can not be created or tested without the key..
I know I am missing something so the question.. how this be solved?
 

DonManfred

Expert
Licensed User
Longtime User
I found it one must upload (create) a project first in order to get a key
Why? I can create 20 new keys without creating a new project.

  1. Go to the Google Developers Console.
  2. Select a project, or create a new one.
  3. In the sidebar on the left, expand APIs & auth. Next, click APIs. In the list of APIs, make sure the status is ON for the YouTube Data API v3.
  4. In the sidebar on the left, select Credentials.
 

Beja

Expert
Licensed User
Longtime User
Why? I can create 20 new keys without creating a new project.

  1. Go to the Google Developers Console.
  2. Select a project, or create a new one.
  3. In the sidebar on the left, expand APIs & auth. Next, click APIs. In the list of APIs, make sure the status is ON for the YouTube Data API v3.
  4. In the sidebar on the left, select Credentials.

This is what I am talking about.. I must go to the dev console and select an app that's already published. or create (upload) a new one.
but I have a new app that's not published.. the steps up want me to publish it first (steps 1 and 2)
 

JackKirk

Well-Known Member
Licensed User
Longtime User
Hi,

I have managed to get this library running and am now trying to break it - just to see what the user has to have installed etc.

In the initial post in this thread, Erel states:
It requires YouTube app v4.2.16 which is currently the latest version. You can update YouTube from Google Play.

So I dutifully installed the latest YouTube app from the playstore.

However when I now uninstall the YouTube app I find my app running this library still works.

Is the YouTube app a prerequisite or not?

Thanks in anticipation...
 
Last edited:
Top