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

Star-Dust

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

Star-Dust

Expert
Licensed User
Longtime User

MarcoRome

Expert
Licensed User
Longtime User
But I don't know what it means exactly: live streaming?
Example if you want to view a movie on youtube on ExoPlayer the same does not start. If you have the direct link that does not go through you tube, ExoPlayer will be able to stream.
 

Star-Dust

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

LucaMs

Expert
Licensed User
Longtime User
But I don't know what it means exactly: live streaming?
1610560539955.png


I'm O.T., I know; anyway, I had never heard of this Twitch (which belongs to Amazon)
 
Top