B4J Question How to catch MediaPlayer MediaException error?

bdunkleysmith

Active Member
Licensed User
Longtime User
In a previous post Watchdog timer for mediaplayer I successfully sought assistance in implementing a watchdog timer as a means of stepping through a MediaException error thrown by MediaPlayer so the application didn't stall, allowing subsequent videos to play after the watchdog timer expired.

However it seems the error is thrown randomly in that in most cases for the same set of video files no error is thrown, but occasionally one or two different videos don't play and so I don't believe there is anything wrong with the video files as such. I have also investigated a pre-loading technique used in this post Media exception error which I thought may help, but it's rather difficult to implement in my situation.

So I would like to revisit the problem and try to catch the error so I could retry to play the video file rather than show a blank screen for the period of the watchdog timer before playing the next video file in sequence.

Here is an example of what I see in the logs when an error occurs:

BDSSynergyPlayerBoard V12b started at 13/6/2023 21:6:53
Java version: 18.0.1
Host Address: 192.168.0.10
MediaException: UNKNOWN : [com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMediaPlayer@31fd1d64] ERROR_MEDIA_INVALID: ERROR_MEDIA_INVALID
at [email protected]/javafx.scene.media.MediaException.getMediaException(MediaException.java:161)
at [email protected]/javafx.scene.media.MediaPlayer$_MediaErrorListener.onError(MediaPlayer.java:2624)
at [email protected]/com.sun.media.jfxmediaimpl.NativeMediaPlayer$EventQueueThread.HandleErrorEvents(NativeMediaPlayer.java:692)
at [email protected]/com.sun.media.jfxmediaimpl.NativeMediaPlayer$EventQueueThread.run(NativeMediaPlayer.java:426)

Video error for #9
MediaException: UNKNOWN : [com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMediaPlayer@62a64577] ERROR_MEDIA_INVALID: ERROR_MEDIA_INVALID
at [email protected]/javafx.scene.media.MediaException.getMediaException(MediaException.java:161)
at [email protected]/javafx.scene.media.MediaPlayer$_MediaErrorListener.onError(MediaPlayer.java:2624)
at [email protected]/com.sun.media.jfxmediaimpl.NativeMediaPlayer$EventQueueThread.HandleErrorEvents(NativeMediaPlayer.java:692)
at [email protected]/com.sun.media.jfxmediaimpl.NativeMediaPlayer$EventQueueThread.run(NativeMediaPlayer.java:426)

Video error for #20

The first 3 lines are just my standard log entries and the Video error lines are logged when the watchdog timer expires.

I thought I should be able to capture the MediaException errors by using a Try / Catch / End Try around the MediaPlayer code so I could then implement retry code, but it does not appear to capture the error.

Why is it that the MediaException shows in red text in the logs, but a Try / Catch / End Try doesn't capture the exception? In any event, how can I capture the MediaException so I can implement some retry code?

Thanks in anticipation of any assistance.
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Yes @Erel, I am using MediaView:

B4X:
        If File.Exists(PublicApplicationDataFolder & "\Intros\" & cmbOrganisationID.Value, videoFile) = True Then       
            mppp.Initialize("mppp",File.GetUri(PublicApplicationDataFolder & "\Intros\" & cmbOrganisationID.Value, videoFile))
            mv.InitializeNewInstance("javafx.scene.media.MediaView",Array(mppp))
            mMediaViewNode = mv
            Display.fullPane.AddNode(mMediaViewNode,0,0,-1,-1)
            mv.RunMethod("setFitWidth",Array(videoWidth))
            mv.RunMethod("setFitHeight",Array(videoWidth*9/16))
            mMediaViewNode.Visible = True
            mppp.play
            mppp.Volume = 0        'Mute player intro video clips   
            Return True
        Else
            Return False
        End If

Can I catch the error on that different thread?
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
As foreshadowed in my post #4, I investigated use of the custom view: MediaView from this MediaView - video player library and this code replaces that shown in post #3:

B4X:
    If File.Exists(PublicApplicationDataFolder & "\Intros\" & cmbOrganisationID.Value, videoFile) = True Then
        MediaView1.Initialize(Me, "mppp")
        MediaView1.DesignerCreateView(Display.fullPane, Null, Null)
        MediaView1.Source = File.GetUri(PublicApplicationDataFolder & "\Intros\" & cmbOrganisationID.Value, videoFile)
        MediaView1.play
        MediaView1.Volume = 0        'Mute player intro video clips
        Return True
    Else
        Return False
    End If

I made the change with the expectation I'd be able to use the error event available in that library, but inexplicably I am yet to have an error thrown despite repeated testing using the same video files used previously when I did encounter random errors.

Only time will tell if swapping to use of this library has solved the problem and so I'll leave this thread open for a while, but mark it as SOLVED if after a reasonable time no errors are thrown.
 
Last edited:
Upvote 0

MikeH

Well-Known Member
Licensed User
Longtime User
Same situation as:
 
Upvote 0
Top