B4A Library YouTube library

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jan 3, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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.

    [​IMG]

    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:
    Code:
    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"NullTrue)
       
    End If
    End Sub
    Sub PlayVideo_Click
       YouTube.StartVideo(
    "AIzaSyxxxxxxxx-xxxx-xxxxxxxxxxxx", _
          
    "0xdZXOM_Otc"0FalseTrue)
    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.
     

    Attached Files:

    yiankos1, vecino and Douglas Farias like this.
  2. Theera

    Theera Well-Known Member Licensed User

    Hi Erel,
    I tried follow as your guide,but I have some error as belows. Please help me corrected

    Best Regards
    Theera
     
    Last edited: Jan 24, 2013
  3. NJDude

    NJDude Expert Licensed User

    You cannot run that sample on the emulator, the emulator doesn't have the YouTube app installed.
     
  4. Inman

    Inman Well-Known Member Licensed User

    Thanks Erel. That was fast! Tested on my Asus Transformer tablet running Android 4.0 and it works great.

    One issue I noticed is an error at the time of compilation saying there is a duplicate refresh.png entry. I have a refresh.png file already in my app. Do you have a same name file in the YouTube library as well?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Maybe there is such a resource file in the native library. You can open it with a zip program and check.
     
  6. hasanaydin52

    hasanaydin52 Member Licensed User

    Hello Erel,

    I get an error as above.

    ** Activity (main) Pause, UserClosed = false **
    sending message to waiting queue (OnActivityResult)
    running waiting messages (1)
    Result = INTERNAL_ERROR
    ** Activity (main) Resume **
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Try the attached program. Does it work?
     

    Attached Files:

    • 1.apk
      File size:
      115.9 KB
      Views:
      222
    saa3lo likes this.
  8. hasanaydin52

    hasanaydin52 Member Licensed User

    Unfortunately does not response.

    Log messages: 10...9...8..7.... .. ....0

    My phone is Galaxy S2. Android version is 4.1.2 .
     
  9. Inman

    Inman Well-Known Member Licensed User

    I got this error when I didn't set the Version Name and Version Code of the app. Once I did that, it worked flawlessly.
     
    manolis and eSolution like this.
  10. hasanaydin52

    hasanaydin52 Member Licensed User

    Hello Erel,

    Inman is right. It is worked when define the VersionName.

    I did not know how important this is.

    Thanks for library.
     
  11. hasanaydin52

    hasanaydin52 Member Licensed User

    Hello Erel,

    StartVideo function running good but i can't run StartPlaylist.


    Code:
    YouTube.StartPlaylist("AIza....","ballislife",0,1000,True,True)
    Result 404 Network Error....
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Did my example (APK file) work or not?

    Make sure that you are using the correct ID.
     
  13. hasanaydin52

    hasanaydin52 Member Licensed User

    Your 1.apk does not run too.

    My Startvideo example worked fine with same ID.
     
    Last edited: Jan 30, 2013
  14. Erel

    Erel Administrator Staff Member Licensed User

    You need a PlayList id not a video id.
     
  15. hasanaydin52

    hasanaydin52 Member Licensed User

    Sorry I understand as Developer Key ID.

    I used ID as "ballislife" in function but does not run.
    I dont know is "ballislife" true ID.

    Can you send me another sample ID?

    Code:
    YouTube.StartPlaylist("AIza...","ballislife",0,0,False,False)
     
    Last edited: Jan 31, 2013
  16. Erel

    Erel Administrator Staff Member Licensed User

    As written in the documentation you should look for the id after the list parameter.
    Here is one: PL85F43D1287E29191
     
  17. hasanaydin52

    hasanaydin52 Member Licensed User

    Hello Erel,

    I mixed ChannelID and PlaylistID.

    it's OK.

    Thank you very much.
     
  18. AndroIwe

    AndroIwe Member Licensed User

    Thank you for this example.

    I want to load the video on a specific position and tried it with "Activity.AddView":

    Code:
    Sub Globals
        
    Dim YouTube As YouTubeStandalonePlayer
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    Activity.LoadLayout("YouTubeTest1")
       YouTube.Initialize(
    "YouTube")
        
    Activity.AddView(YouTube, 10dip10dip250dip400dip)   
       
    If YouTube.CheckPlayerSupported <> "SUCCESS" Then
            
    Msgbox("YouTube service not available: " & CRLF & YouTube.CheckPlayerSupported, "")
        
    Else
            
    Activity.AddMenuItem3("Play Video""PlayVideo"NullTrue)
        
    End If
    End Sub
    Sub PlayVideo_Click
        YouTube.StartVideo(
    "AIzaSyDhjNZFx50axXbAxxxxx", _
            
    "kHuSNntPdA8"0TrueTrue)
    End Sub
    But I got an error:
    Is there any way to place the video on a specific position?
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    No. The player starts in its own transparent activity.
     
  20. AndroIwe

    AndroIwe Member Licensed User

    Thank you Erel,

    i feared that ...
     
Loading...