B4A Library [B4X] DL Youtube ExoPlayer

UPDATE 1.22 ( "change" parameters call get_video_info )
BUGFIX UPDATE 1.21 ( "change" Format File json get_info for B4i )
BUGFIX UPDATE 1.20 ( "change" API Youtube )
see:
Hi All.
We all know the excellent ExoPlayer, too bad it doesn't load videos from youtube links. With this Library (B4A, B4i, B4J) it is possible to view the direct youtube link on both ExoPlayer, VideoPlayer and WebView.



The code is very simple:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private player1 As SimpleExoPlayer
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim DL As DLinkYouTube
    Dim ke_y As String = $"YOUR API KEY YOUTUBE"$
    Private B4XImageView1 As B4XImageView
    Private Button1 As Button
    Private SimpleExoPlayerView1 As SimpleExoPlayerView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")

End Sub

Private Sub Button1_Click
    DL.Initialize(ke_y)

    'Put ID YouTube
    Wait For(DL.DirectLinkYT($"EynXt2GVpTg"$)) Complete (Result As Map)
    'Log("Result: " & Result)
    Dim state As String =  Result.Get("state_movie")
    Dim link_movie As String = Result.Get("link_movie")
    Dim pic As String = Result.Get("link_immagine")
    Dim movie_mute As String = Result.Get("link_movie_mute")
    If state = "UNPLAYABLE" Then
        Log("Result: Video not available")
    Else
        'Load DL Youtube
        'Log($"${link_movie}"$)
        player1.Initialize("player")
        Dim sources As List
        sources.Initialize
        sources.Add(player1.CreateUriSource($"${link_movie}"$))
        '.....
        player1.Prepare(player1.CreateListSource(sources))
        SimpleExoPlayerView1.Player = player1
        player1.Play
        'Load Imagine YouTube
        DownloadImage(pic, B4XImageView1)
    End If
End Sub


'Per Caricare immagine singola
Sub DownloadImage(Link As String, iv As B4XImageView)
    Dim job As HttpJob
    job.Initialize("", Me) 'note that the name parameter is no longer needed.
    job.Download(Link)

    Wait For (job) JobDone(job As HttpJob)
    If job.Success Then
        iv.Bitmap = job.GetBitmap
    End If
    job.Release
End Sub
 

Attachments

  • LibraryDLExample.zip
    22.4 KB · Views: 955
  • DLYoutube.b4xlib
    1.9 KB · Views: 721
Last edited:

jahswant

Well-Known Member
Licensed User
Longtime User
Any clue ?
B4X:
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
*** Service (httpsendingservice) Create ***
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httpsendingservice) Start **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = true **
** Activity (pagesactivity) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (pagesactivity) Resume **
** Service (httpsendingservice) Destroy **
NonQuery: true
NonQuery: true
dlinkyoutube$ResumableSub_DirectLinkYTresume (java line: 209)
java.lang.RuntimeException: Object should first be initialized (Map).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:64)
    at tc.rndt.lereveil.dlinkyoutube$ResumableSub_DirectLinkYT.resume(dlinkyoutube.java:209)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:264)
    at android.app.ActivityThread.main(ActivityThread.java:7510)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
 

MarcoRome

Expert
Licensed User
Longtime User
This isnt example in attahcment, i see:
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Where is your code ??
 

jahswant

Well-Known Member
Licensed User
Longtime User
This isnt example in attahcment, i see:
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Where is your code ??
I found out that this happens when the video is private. In public one all is OK. Thanks
 

MarcoRome

Expert
Licensed User
Longtime User
I found out that this happens when the video is private. In public one all is OK. Thanks
If you see example in first post , you see that is possible check if private or no
 
Last edited:

dongsool

Member
Licensed User
Longtime User
I tested it, and I got this error message.

B4X:
ResponseError. Reason: , Response: <html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>Sorry...</title><style> body { font-family: verdana, arial, sans-serif; background-color: #fff; color: #000; }</style></head><body><div><table><tr><td><b><font face=sans-serif size=10><font color=#4285f4>G</font><font color=#ea4335>o</font><font color=#fbbc05>o</font><font color=#4285f4>g</font><font color=#34a853>l</font><font color=#ea4335>e</font></font></b></td><td style="text-align: left; vertical-align: bottom; padding-bottom: 15px; width: 50%"><div style="border-bottom: 1px solid #dfdfdf;">Sorry...</div></td></tr></table></div><div style="margin-left: 4em;"><h1>We're sorry...</h1><p>... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.</p></div><div style="margin-left: 4em;">See <a href="https://support.google.com/websearch/answer/86640">Google Help</a> for more information.<br/><br/></div><div style="text-align: center; border-top: 1px solid #dfdfdf;"><a href="https://www.google.com">Google Home</a></div></body></html>
 

Attachments

  • Screenshot_94.png
    16.2 KB · Views: 296

MarcoRome

Expert
Licensed User
Longtime User

This is because Google changed the get_video_info function once again (a week ago).
In 3 months he made the following changes:

The current address to use get_video_info not known (by me), if you know the new call to get_video_info, it can be fixed in 2 minutes.
 

victormedranop

Well-Known Member
Licensed User
Longtime User
question, in this part

B4X:
Wait For(DL.DirectLinkYT($"nwimMVC2v5k"$)) Complete (Result As Map)

is for url video ->
am trying the demo

i just got no video
ResponseError. Reason: , Response:
Result: Video non disponibile
 

MarcoRome

Expert
Licensed User
Longtime User

Look thread 29
The current address to use get_video_info not known (by me), if you know the new call to get_video_info, it can be fixed in 2 minutes.
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Use the new SimpleMediaManager library


By inserting the direct link of the youtube movie (copy the link in the embed code)
 

Almora

Well-Known Member
Licensed User
Longtime User
hi..
does this method cause a google Play policy violation?


update::: I think there is a problem..
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
hi..
does this method cause a google Play policy violation?


update::: I think there is a problem..


 

MarcoRome

Expert
Licensed User
Longtime User
Will this work with Youtube Live broadcasts?

No, I do not think. You should use APIsStart with API

You can see this example:

 

hatzisn

Expert
Licensed User
Longtime User
Have I done anything wrong?

All the videos I tried return UNPLAYABLE even your orginal video ID @MarcoRome. I have Android 12.
I keep seeing in the logs (Video non disponibile).
 

MarcoRome

Expert
Licensed User
Longtime User
Have I done anything wrong?

All the videos I tried return UNPLAYABLE even your orginal video ID @MarcoRome. I have Android 12.
I keep seeing in the logs (Video non disponibile).

Why don't you read the previous threads ?

See:

 

hatzisn

Expert
Licensed User
Longtime User
Use the new SimpleMediaManager library



By inserting the direct link of the youtube movie (copy the link in the embed code)

I tested this in Android TV and it displays indeed the video in ExoPlayer but I cannot get it to start. What should be done for this? Since it seems like you are more advanced in this , are you aware of any solution on this?
 

MarcoRome

Expert
Licensed User
Longtime User
I tested this in Android TV and it displays indeed the video in ExoPlayer but I cannot get it to start. What should be done for this? Since it seems like you are more advanced in this , are you aware of any solution on this?

But on the android device ( smartphone or tablet ) it works ?
Anyway is preferable open a new thread
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…