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,189
  • ExoPlayer.zip
    10.1 KB · Views: 2,677
Last edited:

DonManfred

Expert
Licensed User
Longtime User
If you get the same error then you are still using a reference to one of the old http libs (or classes or services)...

you need to uncheck http lib and you need to uncheck httputils2 lib.
If you are using a httputils2service in your project you need to remove this too.

In fact you need to remove all old http libs and replace them with okHTTP and okhttputils2

If that does not help: Try to reproduce the problem in a small project.
start with a NEW thread in the questions forum uploading your problematic project and the error
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Audio Issue. I have testes Ffmpeg library and have video and audio, but cant manage size of the screen.
right now trying with Exoplayer, but got video no audio.

how can I debug this library, the functions ready, error, complete works.
but need more information.

in the image is the codification of the stream.

Victor Medrano
 

Attachments

  • codec.PNG
    codec.PNG
    8.9 KB · Views: 360
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add the attached class.

Usage example:
B4X:
Sub Process_Globals
   Private player1 As SimpleExoPlayer
   Private playerEx As ExoPlayerExtra
End Sub

Sub Globals
   Private SimpleExoPlayerView1 As SimpleExoPlayerView
   Private Button1 As Button
End Sub

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
   playerEx.Initialize(player1)
End Sub

Sub Button1_Click
   playerEx.CurrentWindowIndex = (playerEx.CurrentWindowIndex + 1) Mod playerEx.WindowCount
End Sub
 

Attachments

  • ExoPlayerExtra.bas
    679 bytes · Views: 721

Erel

B4X founder
Staff member
Licensed User
Longtime User
So why the need for all these very high B4A, Java 7 (not 6) and Tools versions?
I'm not sure whether you are serious or not... Java 7 was released at 2011.

Exoplayer should work with Android API 9+ (not 14+)
SS-2016-12-15_08.18.43.png

https://google.github.io/ExoPlayer/guide.html

Is there really no way to make your Exoplayer library work with earlier SDK Build tools?
Older build tools are not supported by the native library.
I guess that it is time to upgrade from Windows XP to Windows 7+ if you want to use the latest Android libraries and features.
 

zura

New Member
Licensed User
Longtime User
i am getting an error:

Generating R file. Error
invalid resource directory name: C:\Users\user\Documents\Basic4Android\exo.04\Objects\bin\extra\res1\res/values-b+sr+Latn
 

Licht2002

Member
Licensed User
Longtime User
Hello, i get an Error....

..... Suppressed: java.lang.ClassNotFoundException: com.google.android.exoplayer2.upstream.DefaultBandwidthMeter .....

I use the Test-File from Post 1..... with "android-25\android.jar" and "jdk1.8.0_112\bin\javac.exe"...

B4X:
LogCat connected to: B4A-Bridge: samsung SM-G900F
--------- beginning of main
** 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:7224)
    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-2/base.apk"],nativeLibraryDirectories=[/data/app/b4a.ExoPlayer-2/lib/arm, /vendor/lib, /system/lib]]
    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:7224)
    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-2/base.apk"],nativeLibraryDirectories=[/data/app/b4a.ExoPlayer-2/lib/arm, /vendor/lib, /system/lib]]
    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
** Activity (main) Pause, UserClosed = true **
** 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:7224)
    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-2/base.apk"],nativeLibraryDirectories=[/data/app/b4a.ExoPlayer-2/lib/arm, /vendor/lib, /system/lib]]
    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:7224)
    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-2/base.apk"],nativeLibraryDirectories=[/data/app/b4a.ExoPlayer-2/lib/arm, /vendor/lib, /system/lib]]
    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
** Activity (main) Pause, UserClosed = true **

Do i something wrong?

Thx Tom
 

Attachments

  • ExoPlayer_Test.zip
    8 KB · Views: 451

Licht2002

Member
Licensed User
Longtime User
and B4A 6+?
and the maven repos are up-to-date (41)?

Hi DonManfred,

Yes... i check Repos = 41, SDK Tools 25.2.4, API 25 B4A 6.50, ...

I never seen this error before:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/exoplayer2/upstream/DefaultBandwidthMeter;

Thx
Tom
 

Rusty

Well-Known Member
Licensed User
Longtime User
Nice library :)
Is there a way to programatically pause or stop the play?
i.e. VideoView you can VideoView.pause or VideoView.stop.
Thanks
Rusty
 

almontgreen

Active Member
Licensed User
Longtime User
Nice library :)
Is there a way to programatically pause or stop the play?
i.e. VideoView you can VideoView.pause or VideoView.stop.
Thanks
Rusty

Player1.Play
Player1.Pause

In Sub Process_Globals add Private player1 As SimpleExoPlayer

Have to use layout.
You can turn off controls with
SimpleExoPlayerView1.UseController = False
 
Status
Not open for further replies.
Top