B4J Question JavaFx MediaView

udg

Expert
Licensed User
Longtime User
Hi all,
today I quickly prepared a class wrapping the standard MediaView component. It seems to work, but I have a couple of questions for those who know JavaObiect better than me.

1. Is the below code for the OnError event right?
2. Can you provide an example when the OnError code should be triggered?

B4X:
'mp1 is the MediaPlayer object passed on class initialization
   ....
   mv.InitializeNewInstance("javafx.scene.media.MediaView",Array As Object(mp1))
   Dim e As Object = mv.CreateEvent("javafx.event.EventHandler","MVError",False)
   mv.RunMethod("setOnError",Array(e))
   ...
End Sub

Sub MVError_Event(MethodName As String, Args() As Object) As Object  'ignore
   If SubExists(CallBack,EventName&"_OnError") Then CallSub(CallBack,EventName & "_OnError")
   Return True
End Sub

TIA

udg
 

udg

Expert
Licensed User
Longtime User
Thank you Erel.
What kind of error is it supposed to catch?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
eheh.. a bit generic, isn'it? I hoped in something more specific like "wrong file format", "file missing", etc.
BTW, I tried the file missing case and it's catched by MediaPlayer.

Once I clean up a bit my code I'll publish it in the appropriate Forum's section. Do you think it should be available as a CustomView through the Designer or a plain class where the MediaView component is able to be shown on a pane will suffice? You know, when I solve a problem I become laaazy...
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi @Erel ,
I found at least one kind of error on which MediaViews's OnError function reacts. It was the absence of an AAC decoder on my old XP PC that triggered the error, but as you can see from the log below it seems something generated at the MediaPlayer level.
B4X:
MediaException: MEDIA_UNSUPPORTED : [com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMediaPlayer@3e0175] ERROR_MEDIA_AAC_FORMAT_UNSUPPORTED: ERROR_MEDIA_AAC_FORMAT_UNSUPPORTED
error MediaView1       'written by my code when class calls back Main on error
   at javafx.scene.media.MediaException.getMediaException(MediaException.java:160)
   at javafx.scene.media.MediaPlayer$_MediaErrorListener.onError(MediaPlayer.java:2615)
MEDIA_UNSUPPORTED  'written by my code...
   at com.sun.media.jfxmediaimpl.NativeMediaPlayer$EventQueueThread.HandleErrorEvents(NativeMediaPlayer.java:691)
   at com.sun.media.jfxmediaimpl.NativeMediaPlayer$EventQueueThread.run(NativeMediaPlayer.java:425)
If you can confirm my findings, I guess we should trap errors (file missing, wrong format, no decoder..) at MediaPlayer level. Probably there are other kind of errors specific to MediaView we will encounter soon or later..eheh
 
Upvote 0
Top