Wish Adding an error event to videoview?

wimpie3

Well-Known Member
Licensed User
Longtime User
Cool, thanks Erel, but unfortunately I'm using the VideoViewExtras library for layout reasons. So I'd need a combination of both VideoViewExtras and AudioExtras. Any chance you might add these to the Audio library? I presume that everyone who needs VideoView, also wants to receive the error events.

OFF TOPIC: You known, to be honest, that's a general issue I have with B4A after working with your product for over 1,5 years. Some core functionality that seems "evident" to me is missing in B4A (like the error handling in the Audio library). I know the mantra is "there's a library for that", but most libraries aren't perfect either, and in some cases you'd need a combination of two libraries to get all the missing features, which is impossible of course. Yes, I could start writing my own Java libraries, but avoiding Java is the reason I've started with B4A to begin with... Just trying to be constructive here Erel, I appreciate your work, but it's frustrating sometimes when you realize that something simply isn't possible because a library is missing some events or parameters.
 

warwound

Expert
Licensed User
Longtime User
Cool, thanks Erel, but unfortunately I'm using the VideoViewExtras library for layout reasons. So I'd need a combination of both VideoViewExtras and AudioExtras. Any chance you might add these to the Audio library? I presume that everyone who needs VideoView, also wants to receive the error events.

What's the problem using both VideoViewExtras and AudioExtras?
I'd expect both to work perfectly well together.

Martin.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I agree that it should have been implemented in Audio library. Not sure why it is missing.

You can however add it with JavaObject:
B4X:
Sub AddErrorHandler(v As VideoView, EventName As String)
   Dim jo As JavaObject = v
   Dim e As Object = jo.CreateEventFromUI("android.media.MediaPlayer.OnErrorListener", EventName, True)
   jo.RunMethod("setOnErrorListener", Array(e))
End Sub

For example:
B4X:
Sub Globals
   Dim vv As VideoView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   vv.Initialize("vv")
   Activity.AddView(vv, 0, 0, 300dip, 300dip)
   AddErrorHandler(vv, "VVError")
   vv.LoadVideo(File.DirRootExternal, "1.df")
End Sub

Sub AddErrorHandler(v As VideoView, EventName As String)
   Dim jo As JavaObject = v
   Dim e As Object = jo.CreateEventFromUI("android.media.MediaPlayer.OnErrorListener", EventName, True)
   jo.RunMethod("setOnErrorListener", Array(e))
End Sub

Sub VVError_Event (MethodName As String, Args() As Object) As Object
   Dim what As Int = args(1)
   Dim extra As Int = args(2)
   Return Null
End Sub

The error codes are documented here: http://developer.android.com/reference/android/media/MediaPlayer.OnErrorListener.html
 

wimpie3

Well-Known Member
Licensed User
Longtime User
THANKS! Might be a good idea to add this to the Audio library anyway.
 
Top