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. ExoPlayer is an internal library, starting with B4A v13.4.
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.11 - Added missing dependency (androidx.core:core-ktx)
v3.10 - Updated dependencies. Requires B4A v13.4+ with an updated SDK. This is an internal library now.
v3.02 - Updated dependencies.
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: 1,452
  • ExoPlayer.zip
    9.3 KB · Views: 89
Last edited:

Theera

Expert
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.
 

cbal03

Active Member
Licensed User
Longtime User
I ran the sample. It compiles and loads onto the device but when line 21 in B4xMainPage is executed the app crashes with error:
Error occurred on line: 21 (B4XMainPage)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)

if i stop execution in dubug mode on line 21 all is well.

B4A ver. 13.4

I followed the instructions in the first post to get it going.
Any ideas?
Thanks!


fixed it.
files in this post are older.

found the correct ones here: https://www.b4x.com/android/forum/threads/exoplayer-mediaplayer-videoview-alternative.72652/#content
for anyone else using older duplicate files.
 

Attachments

  • ExoPlayerExample.zip
    14.2 KB · Views: 54
Last edited:

Toley

Active Member
Licensed User
Longtime User
This example crash on two different devices if I press the configuration button and after anywhere else. Can someone try it please?
Here is the log.
Log:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/view/ViewGroupKt;
    at androidx.customview.poolingcontainer.PoolingContainer.callPoolingContainerOnReleaseForChildren(PoolingContainer.kt:111)
    at androidx.recyclerview.widget.RecyclerView.onDetachedFromWindow(RecyclerView.java:3541)
    at android.view.View.dispatchDetachedFromWindow(View.java:17498)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3701)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3693)
    at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3474)
    at android.view.ViewRootImpl.doDie(ViewRootImpl.java:6329)
    at android.view.ViewRootImpl.die(ViewRootImpl.java:6306)
    at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:458)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:396)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:124)
    at android.widget.PopupWindow.dismissImmediate(PopupWindow.java:1986)
    at android.widget.PopupWindow.dismiss(PopupWindow.java:1929)
    at android.widget.PopupWindow$PopupDecorView.onTouchEvent(PopupWindow.java:2416)
    at android.view.View.dispatchTouchEvent(View.java:11776)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2962)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2643)
    at android.widget.PopupWindow$PopupDecorView.dispatchTouchEvent(PopupWindow.java:2406)
    at android.view.View.dispatchPointerEvent(View.java:12015)
    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795)
    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661)
    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635)
    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596)
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764)
    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:325)
    at android.os.Looper.loop(Looper.java:142)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewGroupKt" on path: DexPathList[[zip file "/data/app/b4a.example-Xh31Etl9n3RzdDeIeNh2Ow==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-Xh31Etl9n3RzdDeIeNh2Ow==/lib/arm, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 44 more
 
Top