B4A Library addoMedia3 - AndroidX Media3 Exoplayer Wrapper

This library is wrapper for the new AndroidX Media3 Library which is based on Exoplayer You can still use my previous wrapper.
Since from now on the new updates and releases will be Published to AndroidX Media3 Library. so i migrate the whole wrapper to the new codebase.

Version 1.2.0 required aar.
Additional AAR 1.2.0

Functionality :
  • CreateUriSource
  • CreateSmoothStreamingSource
  • CreateHLSSource
  • CreateDashSource
  • CreateFileSource
  • CreateRtspStreamingSource
  • CreateRtmpStreamingSource
  • CreateUdpStreamingSource
  • PlayList
  • clearMediaItems
  • CreateListSource[Deprecated].
  • setReapeatMode
  • getIsPlaying
  • Prepare
  • Play
  • Pause
  • Release
  • getPosition
  • setPosition
  • getDuration
  • getVolume
  • setVolume
  • getCurrentMediaItemIndex
  • GetvideoFormatwidth
  • GetvideoFormatHeight
  • GetAudioTracksLanguages
  • GetVideoTrackSubtitles
  • preferedAudioLanguage
  • preferedtextLanguage
  • EnableSubtitles
  • PlaybackSpeed

DesignerProperties
  • Media3PlayerView
  • ResizeMode [FIT|FIXED_HEIGHT|FIXED_WIDTH]
  • UseController default is true
  • ShowBuffering [NEVER|PLAYING|ALWAYS] default is NEVER
  • ControllerTimeout default is 5000
Events :
  • Player_Ready
  • Player_Error
  • Player_Complete
  • Player_MetaData(metadataFields As Map)
  • IDLE
  • Buffering
Library and Example attached. Don't forget to download the required media3 aars, have a good day.

Updated to version 1.3

Added

  • TrackMetadata
  • PlaybackSpeed
B4X:
Sub Player_Ready
    addoPlayer.TrackMetadata
    Log("Ready")
End Sub

'example of calling th event

Sub Player_MetaData(metadataFields As Map)
    Log(metadataFields)
    Label1.Text = ""
    If metadataFields.ContainsKey("Title") Then
        Label1.Text = metadataFields.Get("Title")
    End If
    ' Handle the metadata fields here
    If metadataFields.ContainsKey("ArtworkData") Then
        Dim artworkData() As Byte = metadataFields.Get("ArtworkData")
        ' Create an InputStream from the byte array
        Dim inp As InputStream
        inp.InitializeFromBytesArray(artworkData, 0, artworkData.Length)
        ' Create a Bitmap from the InputStream
        Dim bitmap As Bitmap
        bitmap.Initialize2(inp)
        ImageView1.Bitmap = bitmap
        ImageView1.Visible = True
    End If
End Sub

Updated Media3 to the latest 1.2.0

I may add more features to this library..
 

Attachments

  • addoMedia3-V-1.3.zip
    19 KB · Views: 123
Last edited:

Almora

Active Member
Licensed User
Longtime User
... with package name com.google.android.exoplayer2, will soon be discontinued, so to continue receiving updates, you will need to migrate to Media3 ExoPlayer.

 
Last edited:

Enxix

Member
Hello, The bookstore is appreciated. I was using the previous wrapper and I really like it a lot.
The only thing I see (and it is in almost all libraries is that we cannot instantiate the exoplayer2 object) this is so that if in the future we want to extend your library through javaobject or reflection , it will be easier for us.
Could you add the request?
 

Sjuanj

Member
Hello, thanks for sharing this library.
I have some dash links that are encrypted with drm, I have the keyid and the key, but I don't know how I could get into this library.
I know that exoplayer works with these links because I know some apks that work well.
Here it says how to do it with exoplayer: https://github.com/google/ExoPlayer/issues/3201

Can someone guide me how I could do it with b4a?
Thank you
 

Enxix

Member
Hello, The bookstore is appreciated. I was using the previous wrapper and I really like it a lot.
The only thing I see (and it is in almost all libraries is that we cannot instantiate the exoplayer2 object) this is so that if in the future we want to extend your library through javaobject or reflection , it will be easier for us.
Could you add the request?
Sorry to be pushy but I use your library and I would like you to modify it to be able to access the Exoplayer object. that you must have it with @Hide set, that's why I can't access it
 

Addo

Well-Known Member
Licensed User
Hello, thanks for sharing this library.
I have some dash links that are encrypted with drm, I have the keyid and the key, but I don't know how I could get into this library.
I know that exoplayer works with these links because I know some apks that work well.
Here it says how to do it with exoplayer: https://github.com/google/ExoPlayer/issues/3201

Can someone guide me how I could do it with b4a?
Thank you
what kind of solution you are referring to ?
 

Sjuanj

Member
what kind of solution you are referring to ?
Thanks for the reply

I am using google translator, I hope it is understood well.

Dash files (*.mpd) may have drm ( digital rights management ) protection. There are several types: widevine (Netflix, Disney+, Amazon Prime Video...), or clearkey (dazn, movistar+...).

With very few lines of code it can be implemented in exoplayer with android studio, I suppose it wouldn't be very difficult to do it in b4a, because I already told you that there is very little code to put on it. That would make our apks very attractive...

I leave you the link of an apk that works with clearkey so you can see how easy it is (at least it seems so to me, but my knowledge of creating a b4a library is very limited)


Thanks for your time.
 

nedium

Active Member
Licensed User
Longtime User
hello @Addo

I have been following your work for a long time, I wanted to know if the previous library (Exoplayer 2.18.5 Streams Player), will cease to exist and I must migrate everything to this new library.

It is to know if I should migrate everything, since this library is better and has better functions, (It does not cost me anything to migrate)

thanks for your time.
 
Last edited:

Addo

Well-Known Member
Licensed User
hello @Addo

I have been following your work for a long time, I wanted to know if the previous library (Exoplayer 2.18.5 Streams Player), will cease to exist and I must migrate everything to this new library.

It is to know if I should migrate everything, since this library is better and has better functions, (It does not cost me anything to migrate)

thanks for your time.
This library will be the future library for Exoplayer. I put in consideration to add ffmpeg to it in next release. I am just not available as before due to some circumstances in real life. How ever i will be back soon to release even more libraries. Although will take reading meta data into consideration.
 

nedium

Active Member
Licensed User
Longtime User
This library will be the future library for Exoplayer. I put in consideration to add ffmpeg to it in next release. I am just not available as before due to some circumstances in real life. How ever i will be back soon to release even more libraries. Although will take reading meta data into consideration.
Hello, thank you very much for answering.
Considering that in the future it will be the exoplayer library, I will update to this version.
I hope to see you here soon and that everything goes well.
Thank you very much for your time and work. good day
 

nedium

Active Member
Licensed User
Longtime User
Hello

Error: androidx.media3.datasource.HttpDataSource$HttpDataSourceException: javax.net.ssl.SSLPeerUnverifiedException: Hostname NAMEHOST not verified:
or
Error: androidx.media3.datasource.HttpDataSource$HttpDataSourceException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Is there a way to bypass the certificate validation? or accept it
 
Last edited:

nedium

Active Member
Licensed User
Longtime User
Hello @Addo , trying to play an ur from a .MKV file, it gives me the following error.

Error: androidx.media3.exoplayer.video.MediaCodecVideoDecoderException: Decoder failed: c2.mtk.hevc.decoder

Thank you
 

nedium

Active Member
Licensed User
Longtime User
Hello, @Addo

Could you share some example of the use of

GetAudioTracksLanguages
GetVideoTrackSubtitles
preferredAudioLanguage
preferredtextLanguage
EnableSubtitles

I try with the example of the previous version that you had of exoplayer2, but it does not read all the audios, I try it with vlc and 2 audio tracks come out and in your example it only shows me 1.
 

Addo

Well-Known Member
Licensed User
Updated to version 1.2

Added

  • TrackMetadata
B4X:
Sub Player_Ready
    addoPlayer.TrackMetadata
    Log("Ready")
End Sub

'example of calling th event

Sub Player_MetaData(metadataFields As Map)
    Log(metadataFields)
    Label1.Text = ""
    If metadataFields.ContainsKey("Title") Then
        Label1.Text = metadataFields.Get("Title")
    End If
    ' Handle the metadata fields here
    If metadataFields.ContainsKey("ArtworkData") Then
        Dim artworkData() As Byte = metadataFields.Get("ArtworkData")
        ' Create an InputStream from the byte array
        Dim inp As InputStream
        inp.InitializeFromBytesArray(artworkData, 0, artworkData.Length)
        ' Create a Bitmap from the InputStream
        Dim bitmap As Bitmap
        bitmap.Initialize2(inp)
        ImageView1.Bitmap = bitmap
        ImageView1.Visible = True
    End If
End Sub
 
Top