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

victormedranop

Well-Known Member
Licensed User
Longtime User
Thanks DonManfred, but when a try to download the file, download a filename exoplayer.zip.
I don't know what to do with this, renamed?

thanks.

Victor
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Downloaded with chrome, file ok no name modification.
but got error

B4X:
java.lang.NoSuchMethodError: anywheresoftware.b4a.objects.CustomViewWrapper.replaceBaseWithView2
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Simple code "Same Error"
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 = True Then 
 
      player1.Initialize("player1")
      player1.Prepare(player1.CreateHLSSource("http://209.16.115.42:25055"))
 
 End If
 
Activity.LoadLayout("Main")
 
 SimpleExoPlayerView1.Player = player1 
 player1.Play

End Sub
 

victormedranop

Well-Known Member
Licensed User
Longtime User
without any code just adding in the desingner the SimpleExoPlayerView1, crash.
don't know what is happening.

waiting for help. Please
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Full Output
B4X:
Installing file.
PackageAdded: package:net.nowyouseeme.dtv
** Activity (main) Create, isFirst = true **
java.lang.NoSuchMethodError: No static method replaceBaseWithView2(Lanywheresoftware/b4a/objects/PanelWrapper;Landroid/view/View;)V in class Lanywheresoftware/b4a/objects/CustomViewWrapper; or its super classes (declaration of 'anywheresoftware.b4a.objects.CustomViewWrapper' appears in /data/app/net.nowyouseeme.dtv-2/base.apk)
 at anywheresoftware.b4a.objects.SimpleExoPlayerViewWrapper.DesignerCreateView(SimpleExoPlayerViewWrapper.java:41)
 at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:70)
 at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
 at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
 at java.lang.reflect.Method.invoke(Native Method)
 at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
 at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
 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 net.nowyouseeme.dtv.main.afterFirstLayout(main.java:102)
 at net.nowyouseeme.dtv.main.access$000(main.java:17)
 at net.nowyouseeme.dtv.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:148)
 at android.app.ActivityThread.main(ActivityThread.java:5417)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
** Activity (main) Resume **
 

sule

Member
Licensed User
Longtime User
What ever I try i get same error
Generating R file. Error
invalid resource directory name: C:\Users\nn\Desktop\B4A Samples\Objects\bin\extra\res1\res/drawable-xxhdpi-v4
invalid resource directory name: C:\Users\nn\Desktop\B4A Samples\Objects\bin\extra\res1\res/values-b+sr+Latn

i have latest b4a and sdk build tools
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
What ever I try i get same error
Generating R file. Error
invalid resource directory name: C:\Users\nn\Desktop\B4A Samples\Objects\bin\extra\res1\res/drawable-xxhdpi-v4
invalid resource directory name: C:\Users\nn\Desktop\B4A Samples\Objects\bin\extra\res1\res/values-b+sr+Latn

i have latest b4a and sdk build tools
Can you post a screenshot of your Android SDK Manager?
 

sule

Member
Licensed User
Longtime User
1. Are you sure that the IDE is configured to use this SDK (under Tools - Configure Paths)?
2. Try to delete build tools 23.0.1 and 23.0.3.
yes it is configured corectly and i have one more error with http, okhttp ,httputils2 and okhttputils
15135773_1384877828188892_7875331278017902561_n.jpg
 

sule

Member
Licensed User
Longtime User
Which android.jar did you specify in the IDE -> Configure Paths?
It should be from platform 23 or 24

Based on
https://developer.android.com/refer...ce.html#onTaskRemoved(android.content.Intent)
it should be api 14 or higher.

I suggest to use the most up-to-date android.jar
Which android.jar did you specify in the IDE -> Configure Paths?
It should be from platform 23 or 24

Based on
https://developer.android.com/refer...ce.html#onTaskRemoved(android.content.Intent)
it should be api 14 or higher.

I suggest to use the most up-to-date android.jar
15203403_1384923894850952_2900640909314305553_n.jpg
 
Status
Not open for further replies.
Top