B4A Library ExoPlayer - MediaPlayer / VideoView Alternative

Not open for further replies.
ExoPlayer is an open source project that replaces the native MediaPlayer and VideoView types.
License: Apache 2.0

It supports more media formats, it is more powerful and more customizable.
It is supported by Android 4.1+ (API 16+).


There are two types: SimpleExoPlayer and SimpleExoPlayerView.

SimpleExoPlayer is the internal engine, it is similar to MediaPlayer. SimpleExoPlayerView provides the interface.
SimpleExoPlayer can be used without the interface.
SimpleExoPlayer should be a process global variable.

Example of video playback from an asset file (same exact code will work with audio files as well):
Sub Process_Globals
   Private player1 As SimpleExoPlayer
End Sub

Sub Globals
   Private SimpleExoPlayerView1 As SimpleExoPlayerView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     player1.Prepare(player1.CreateFileSource(File.DirAssets, "BLE_Chat.mp4"))
   End If
   SimpleExoPlayerView1.Player = player1 'Connect the interface to the engine
End Sub
You can use player.CreateUriSource to load a remote resource:
Or you can use one of the following methods for streaming resources:

CreateHLSSource - Http Live Streaming
CreateDashSource - Dynamic Adaptive Streaming over Http
CreateSmoothStreamingSource - Smooth Streaming

You can also create a playlist with multiple sources:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     Dim sources As List

   End If
   SimpleExoPlayerView1.Player = player1
End Sub

The library is attached.

It depends on several additional aar files (should be copied to the additional libraries folder):


V1.52 - Previous fix was incomplete. New version solves the issue.
V1.51 - Fixes an incompatibility between ExoPlayer and Firebase. Make sure to update the additional libs package.
V1.50 - New version based on ExoPlayer 2.13.3 (https://github.com/google/ExoPlayer/blob/release-v2/RELEASENOTES.md). The additional libs package was also updated.
V1.41 - Fixes a bug where the designer properties where missing.
V1.40 - Based on ExoPlayer v2.11.3. Make sure to update the additional libs as well.

V1.30 - New InitializeCustom method that allows creating the native player with JavaObject.

V1.20 - Based on ExoPlayer v2.10.2. This is a large update. Not all existing customizations (based on JavaObject) will work without modifications.

V1.10 - Based on ExoPlayer v2.5.3.

Make sure to update the additional aar files as well.


  • ExoPlayerExample.zip
    14 KB · Views: 1,010
  • ExoPlayer.zip
    10.1 KB · Views: 146
Last edited:


Active Member
Licensed User
How can i play https video in exoplayer? Because when i try to play in VLC, for example, It ask me to accept the certificate. Is there a way to do this in exoplayer?

I get the following error Error: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://.....rest of the link
There are examples here : https://www.b4x.com/android/forum/threads/exoplayer-mediaplayer-videoview-alternative.72652/#content

You may need to get the direct link for the video you wish to stream. In the past I have used YouTube-dl Which is not a library but an executable I ran on my computer. Sometimes you can find a direct link in the source code of the webpage. Not simplistic nore automated approach though.
Not open for further replies.