B4A Library ExoPlayer (media3) - video player

ExoPlayer is a powerful media player created by Google: https://developer.android.com/guide/topics/media/exoplayer

This version is based on Media3 ExoPlayer v1.2. It replaces ExoPlayer 2: https://www.b4x.com/android/forum/threads/exoplayer-mediaplayer-videoview-alternative.72652/#content
The underlying SDK isn't backward compatible so calls with JavaObject may not work without modifications.

Setup:
1. Download the attached library and copy to the additional libraries folder.
2. Download the additional dependencies and copy to the additional libraries folder: https://www.b4x.com/android/files/exoplayer3_additional.zip

Usage instructions:
1. Add a SimpleExoPlayerView with the designer.
2. Declare and initialize a SimpleExoPlayer object.
3. Set the player:
B4X:
SimpleExoPlayerView1.Player = Player
4. Create one or more sources with the various "create" methods and call Player.Prepare to load them.

Example is attached.

1703503333084.png


Note that you can use SMM to manage and load videos: [B4X] SimpleMediaManager (SMM) - framework for images, videos and more


Updates:
v3.02 - Updated dependencies. Requires B4A v13.0+ with an updated Android SDK.
v3.01 - Fixes a compatibility issue with Firebase libraries. The dependencies package was updated as well (step #2 above).
 

Attachments

  • ExoPlayerExample.zip
    14.2 KB · Views: 805
  • ExoPlayer.zip
    9.3 KB · Views: 454
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
Is there exoplayer-additional_libs? I have only get the old version.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this:
B4X:
Private Sub CreateUriSource(Uri As String) As Object
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim DataSource As JavaObject = HttpDataSourceFactory.RunMethod("createDataSource", Null)

    DataSource.RunMethod("setRequestProperty", Array("header", "value")) 'set headers here

    Dim DataSourceFactory As JavaObject = ctxt.CreateEvent("androidx.media3.datasource.DataSource.Factory", "", DataSource)
    Dim ProgressiveMediaSourceFactory As JavaObject
    ProgressiveMediaSourceFactory.InitializeNewInstance("androidx.media3.exoplayer.source.ProgressiveMediaSource.Factory", Array(DataSourceFactory))
    Dim MediaItem As JavaObject
    MediaItem.InitializeStatic("androidx.media3.common.MediaItem")
    Return ProgressiveMediaSourceFactory.RunMethod("createMediaSource", Array(MediaItem.RunMethod("fromUri", Array(Uri))))
End Sub
 

josejad

Expert
Licensed User
Longtime User
how can i update my b4a v12.80 to v13.0

Follow carefully the instructions

 

zedapp

Member
thanx, josejad, i have update it but i have an err when i debug my app, the err with : root.loadlayout("MainPage"), it was works in v12.80 !
 
Dear MR Rel,
Please could you send Me a code which is able to hyde build in Exoplayer GUI user interface with buttons for controlling The playback?
Or is it impossible?
I want to make a little vocabulary player for Me. It will play recorded German words and their meaning in Czech so i want to play local file from Assets folder. There will be only two buttons previous Word and Next word.
And i do not have Exoplayer build in GUI interface controls so I could simply swipe between two buttons to play words and The phrases on future.
Thank you very much.
 
Top