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 )
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:

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)

End Sub

Private Sub Button1_Click

    '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")
        'Load DL Youtube
        Dim sources As List
        SimpleExoPlayerView1.Player = player1
        '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.

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


  • LibraryDLExample.zip
    22.4 KB · Views: 813
  • DLYoutube.b4xlib
    1.9 KB · Views: 598
Last edited:


Well-Known Member
Licensed User
Longtime User
But on the android device ( smartphone or tablet ) it works ?
Anyway is preferable open a new thread

It seems at last that it is not an exoplayer at all and probalbly just a webview. I will open a new thread for this.