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.


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:
Sub Process_Globals

End Sub

Sub Globals
   Dim YouTube As YouTubeStandalonePlayer
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If YouTube.CheckPlayerSupported <> "SUCCESS" Then
      Msgbox("YouTube service not available: " & CRLF & YouTube.CheckPlayerSupported, "")
      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.


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


Licensed User
any other code use YouTubePlayerView instead of YouTubeStandalonePlayer
YouTubePlayerView give more control on player
the library is based on YouTubeStandalonePlayer.
For YouTubePlayerView you need to write a wrapper/library first.


Licensed User
Is there any change occurs in this library?
I use it in my own app to embed my youtube channel video.
But since last two or three days, there is not play youtube video more than one time. Video paused automatically. and not play after then.
please inform me for any update.