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

Beja

Expert
Licensed 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
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:

JackKirk

Well-Known Member
Licensed User
Erel,

I did a bit of a google - it appears that the YouTube app is a "system app" - you don't actually uninstall it - you disable it - which was not very clear to me when I did it.

I'm guessing this means whatever low level libraries that the B4A YouTube library is dependant on are still there - and therefor it still works.

I guess it also means I don't have to tell the user of my app that he needs to install the YouTube app - unless he has a rooted device and has managed to really delete it - in which case he can look after himself.

Well I've learnt something - you probably haven't:)

Sorry for using your valuable time and thanks for your speedy response...
 

rafaelbr20

Member
Licensed User
Hi Everyone,

I'm having some problems to play some videos.

ERROR: "An error occurred touch to retry

Videos ID's i can Play
6h7zBG8m3vM
1wTOoharCeg
b_7CERpi3jc

Videos ID's having problem to play
jiN8M8vjgvQ
QZmPbW8W0TU
-FCgoCeWIK0

There is some video blocking from some channels or something like that ?

Thanks
 

Attachments

  • WhatsApp Image 2017-03-09 at 23.08.30.jpeg
    WhatsApp Image 2017-03-09 at 23.08.30.jpeg
    35.5 KB · Views: 110

MarcoRome

Expert
Licensed User
Hi Everyone,

I'm having some problems to play some videos.

ERROR: "An error occurred touch to retry

Videos ID's i can Play
6h7zBG8m3vM
1wTOoharCeg
b_7CERpi3jc

Videos ID's having problem to play
jiN8M8vjgvQ
QZmPbW8W0TU
-FCgoCeWIK0

There is some video blocking from some channels or something like that ?

Thanks
Try this new library EXOPLAYER by @Erel
 

MarcoRome

Expert
Licensed User
Hi Everyone,

I'm having some problems to play some videos.

ERROR: "An error occurred touch to retry

Videos ID's i can Play
6h7zBG8m3vM
1wTOoharCeg
b_7CERpi3jc

Videos ID's having problem to play
jiN8M8vjgvQ
QZmPbW8W0TU
-FCgoCeWIK0

There is some video blocking from some channels or something like that ?

Thanks
I tried this: jiN8M8vjgvQ and work

Screenshot_20170310-071311.jpg
 

hanyelmehy

Active Member
Licensed User
Can we have more control on the player , For Example hide youtube icon ,Removing elements from within the YouTubePlayerView
 

hanyelmehy

Active Member
Licensed User
No. Nothing is configurable.
Thank you for your answer
as i read Starting from version 4.1.7 (android-youtube-player) you can remove all the controls at the bottom, individually.
for example:
youTubePlayerView.getPlayerUIController().showCurrentTime(false);
youTubePlayerView.getPlayerUIController().showSeekBar(false);
youTubePlayerView.getPlayerUIController().showDuration(false);
youTubePlayerView.getPlayerUIController().showYouTubeButton(false);
youTubePlayerView.getPlayerUIController().showFullscreenButton(false);

can we apply that on current library ,or can you please share library code
Thank you
 
Top