B4A Library [B4X] DL Youtube ExoPlayer

MarcoRome

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

Star-Dust

Expert
Licensed User
I wonder, which libraries does it depend on for each platform?
 

Star-Dust

Expert
Licensed User

Star-Dust

Expert
Licensed User
I opened the project and copied the library. Says there is no SimpleExoPlayer class.
 
Top