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: 954
  • DLYoutube.b4xlib
    1.9 KB · Views: 720
Last edited:

hatzisn

Expert
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.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…