B4A Library ExoPlayer - MediaPlayer / VideoView Alternative

Status
Not open for further replies.
Edit: new version: https://www.b4x.com/android/forum/threads/exoplayer-media3-video-player.158204/

ExoPlayer is an open source project that replaces the native MediaPlayer and VideoView types.
https://google.github.io/ExoPlayer/
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+).

upload_2016-11-3_17-10-9.png


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):
B4X:
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.Initialize("player")
     player1.Prepare(player1.CreateFileSource(File.DirAssets, "BLE_Chat.mp4"))
   End If
   Activity.LoadLayout("1")
   SimpleExoPlayerView1.Player = player1 'Connect the interface to the engine
End Sub
You can use player.CreateUriSource to load a remote resource:
B4X:
player1.Prepare(player1.CreateUriSource("https://..."))
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:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     player1.Initialize("player")
     Dim sources As List
     sources.Initialize
     sources.Add(player1.CreateDashSource("http://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0"))
     sources.Add(player1.CreateHLSSource("https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"))
     sources.Add(player1.CreateUriSource("http://html5demos.com/assets/dizzy.mp4"))
     player1.Prepare(player1.CreateListSource(sources))

   End If
   Activity.LoadLayout("1")
   SimpleExoPlayerView1.Player = player1
   player1.Play
End Sub

The library is attached.


It depends on several additional aar files (should be copied to the additional libraries folder):
www.b4x.com/android/files/exoplayer-additional_libs.zip

Updates:

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.
 

Attachments

  • ExoPlayerExample.zip
    14 KB · Views: 3,225
  • ExoPlayer.zip
    10.1 KB · Views: 2,716
Last edited:

Rusty

Well-Known Member
Licensed User
Longtime User
oops...thanks. I was trying to pause the SimpleExoPlayerView...not the SimpleExoPlayer...:oops:
 

lymey

Active Member
Licensed User
Longtime User
ExoPlayer is an open source project that replaces the native MediaPlayer and VideoView types.
https://google.github.io/ExoPlayer/
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+).

Hi Erel,
do you have some examples of what can be customized - is it interface/controls too? Also are there other events, like Paused, is playing, etc?
Many thanks!
 

victormedranop

Well-Known Member
Licensed User
Longtime User
hi, i'm having some problems with fit to tv scale.
try
B4X:
SimpleExoPlayerView1.ResizeMode = "FIT"

but have no effect on.

regards,

Victor
 

Licht2002

Member
Licensed User
Longtime User
Have you copied the aar file to the additional libraries folder?
Hi Erel,

i did everything again:

Load the Libs and store them to: C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries

Load new the Sample from Post #1
Load the aar and store it to: C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries

Load the new Java: C:\Program Files\Java\jdk1.8.0_112\bin\javac.exe

Load the new SDK: C:\Android\platforms\android-25\android.jar


But on all my Devices from 4.1.2 over 4.4 to 6.0.... allways the same error:

B4X:
LogCat connected to: B4A-Bridge: samsung SM-G930F
--------- beginning of main
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
** Service (service1) Destroy **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.Exoplayer
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
Installing file.
PackageAdded: package:b4a.Exoplayer
Installing file.
PackageAdded: package:b4a.Exoplayer
Copying updated assets files (1)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/exoplayer2/upstream/DefaultBandwidthMeter;
    at anywheresoftware.b4a.objects.SimpleExoPlayerWrapper.Initialize(SimpleExoPlayerWrapper.java:73)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:753)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at b4a.Exoplayer.main.afterFirstLayout(main.java:102)
    at b4a.Exoplayer.main.access$000(main.java:17)
    at b4a.Exoplayer.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7229)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.exoplayer2.upstream.DefaultBandwidthMeter" on path: DexPathList[[zip file "/data/app/b4a.Exoplayer-1/base.apk"],nativeLibraryDirectories=[/data/app/b4a.Exoplayer-1/lib/arm64, /vendor/lib64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 17 more
    Suppressed: java.lang.ClassNotFoundException: com.google.android.exoplayer2.upstream.DefaultBandwidthMeter
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 18 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
** Activity (main) Resume **
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/exoplayer2/source/dash/DashMediaSource;
    at anywheresoftware.b4a.objects.SimpleExoPlayerWrapper.CreateDashSource(SimpleExoPlayerWrapper.java:174)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at b4a.Exoplayer.main.afterFirstLayout(main.java:108)
    at b4a.Exoplayer.main.access$000(main.java:17)
    at b4a.Exoplayer.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7229)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.exoplayer2.source.dash.DashMediaSource" on path: DexPathList[[zip file "/data/app/b4a.Exoplayer-1/base.apk"],nativeLibraryDirectories=[/data/app/b4a.Exoplayer-1/lib/arm64, /vendor/lib64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 18 more
    Suppressed: java.lang.ClassNotFoundException: com.google.android.exoplayer2.source.dash.DashMediaSource
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 19 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

What does this line in the error-log mean:
B4X:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.exoplayer2.source.dash.DashMediaSource" on path: DexPathList[[zip file "/data/app/b4a.Exoplayer-1/base.apk"],nativeLibraryDirectories=[/data/app/b4a.Exoplayer-1/lib/arm64, /vendor/lib64, /system/lib64]]





Thx Tom
 
Last edited:

Asim A Baki

Active Member
Licensed User
Longtime User
You cannot. However you can create a layout file with only the SimpleExoPlayerView and load this layout one or more times and do whatever you like with the view.

how to do that? I need to add videoview at runtime
 

almontgreen

Active Member
Licensed User
Longtime User
ExoPlayer is an open source project that replaces the native MediaPlayer and VideoView types.
https://google.github.io/ExoPlayer/
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+).

View attachment 49700

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):
B4X:
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.Initialize("player")
     player1.Prepare(player1.CreateFileSource(File.DirAssets, "BLE_Chat.mp4"))
   End If
   Activity.LoadLayout("1")
   SimpleExoPlayerView1.Player = player1 'Connect the interface to the engine
End Sub
You can use player.CreateUriSource to load a remote resource:
B4X:
player1.Prepare(player1.CreateUriSource("https://..."))
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:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     player1.Initialize("player")
     Dim sources As List
     sources.Initialize
     sources.Add(player1.CreateDashSource("http://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0"))
     sources.Add(player1.CreateHLSSource("https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"))
     sources.Add(player1.CreateUriSource("http://html5demos.com/assets/dizzy.mp4"))
     player1.Prepare(player1.CreateListSource(sources))
  
   End If
   Activity.LoadLayout("1")
   SimpleExoPlayerView1.Player = player1
   player1.Play
End Sub

The library is attached.

It depends on the following aar file (should be copied to the additional libraries folder): www.b4x.com/android/files/exoplayer.aar
 

almontgreen

Active Member
Licensed User
Longtime User
Is there a new version of the ExoPlayer library?

There is new commentary/features here: https://github.com/yangwuan55/ExoPlayer/tree/playbackSpeed

I have offered to pay for mods and for a while had somed3v3loper working on it but there never was any progress and there were many problems I guess? Video playback control is so integral to almost any application that I am at a loss to understand why more work is not being done??? I wish I had the expertise to understand it as I would jump on this... perhaps offering $$thousands instead of $$hundreds would help? I'm about ready to do that as I have several projects in the works that really need a better solution with more features like: position seeking based on frame rate of the encoded file, buffer management, speed control, reverse playback, play to a frame and stop, etc... Am I the only one?
 

biometrics

Active Member
Licensed User
Longtime User
UPDATE: Installed latest API and it's working. Guess I always misunderstood the API numbers, I thought you had to match it with the Android version you're targeting, latest API seems to run fine on Android 4.4.


I'm trying to get ExoPlayer working to replace VideoView.

I have the following installed on Windows 7 64 bit.

B4A 7.01
Java SE Development Kit 8u131
Android SDK r24.4.1
ExoPlayer.jar, ExoPlayer.xml and exoplayer.aar are in this directory: C:\Program Files (x86)\Anywhere Software\Basic4android\Additional Libraries

Android SDK Manager looks as follows (Android Support Repository and Google Repository is also installed):
Android SDK Manager.JPG


Tools/Configure Paths looks as follows:
Paths.JPG


Compiling the sample in the first post in either debug or release mode produces this error (I have replaced our company and product name in the directories with xxx\yyy):

B4X:
B4A version: 7.01
Parsing code.  (0.00s)
Compiling code.  (0.06s)
Compiling layouts code.  (0.00s)
Organizing libraries.  (0.00s)
Generating R file.  Error
C:\Root\xxx\yyy\Player\Android\ExoPlayer\Objects\bin\extra\res1\res\layout\exo_playback_control_view.xml:16: error: No resource identifier found for attribute 'layoutDirection' in package 'android'
C:\Root\xxx\yyy\Player\Android\ExoPlayer\Objects\bin\extra\res1\res\layout\exo_playback_control_view.xml:57: error: No resource identifier found for attribute 'paddingStart' in package 'android'
C:\Root\xxx\yyy\Player\Android\ExoPlayer\Objects\bin\extra\res1\res\layout\exo_playback_control_view.xml:57: error: No resource identifier found for attribute 'paddingEnd' in package 'android'
C:\Root\xxx\yyy\Player\Android\ExoPlayer\Objects\bin\extra\res1\res\layout\exo_playback_control_view.xml:74: error: No resource identifier found for attribute 'paddingEnd' in package 'android'
C:\Root\xxx\yyy\Player\Android\ExoPlayer\Objects\bin\extra\res1\res\layout\exo_playback_control_view.xml:74: error: No resource identifier found for attribute 'paddingStart' in package 'android'

Any ideas why this isn't compiling? Is it perhaps because of the API version?

I've been using API 15 as the devices we used had Android 4.0.3. I understand that ExoPlayer requires API 16. The current devices we use run Android 4.4. Will our app work on Android 4.4 if I replace API 16 it with the latest API if that is required to make ExoPlayer run?
 
Last edited:

biometrics

Active Member
Licensed User
Longtime User
Use the newest android.jar, it has nothing to do with the android version of your device. Install api 25 in sdk manager and remove api 16 tools.
Thanks, I did that a few days ago and it appears to have made the volume setting of VideoView more reliable. Turns out ExoPlayer is too slow, we can't use it. So I've misunderstood the API level for a long time :eek:.
 

Almora

Well-Known Member
Licensed User
Longtime User
hi..
We can check the previous and next buttons as code?
 

Attachments

  • Screenshot_2017-07-18-20-10-35.jpg
    Screenshot_2017-07-18-20-10-35.jpg
    207.3 KB · Views: 434
Status
Not open for further replies.
Top