B4J Question JavaFX MediaView under Win11

bdunkleysmith

Active Member
Licensed User
Longtime User
Some will be aware of several recent posts I've made relating to debugging a problem I've had on a legacy application whereby randomly one or more videos in a sequence of up to 12 videos throws an error, even though at other times the same videos play faultlessly.

For reference here's a couple of those posts Can I do more than MediaView.dispose to make MediaView ready again? and Handling _Finished event in jVLC library.

But while spending countless hours on this problem, my mind kept coming back to what had changed since successfully using the application for several years which may have caused this problem with MediaView given I'd only made minor changes to the application code which related to other functionality over that time. And the thing which stood out, but I discounted, was an upgrade from Win10 to Win11. I'd resisted upgrading because the machine used for this application was stable and performing well, but with end of support approaching for Win10, I updated to Win11 a few months ago and have only had this problem since that upgrade.

Given I’ve spent so much time trying to debug the problem, I was heartened by finding these two references: Video sometimes does not start when reinitializing in Windows 11 and Flaky JavaFX ERROR_MEDIA_INVALID MediaException.

These reinforce/confirm my view that the problem has occurred since updating from Win10 to Win11, particularly as the last comment in the first reference says “Checked with attached testcase in Windows 11, Issue is reproducible . . . . . whereas Issue is not reproducible in Windows 10.” And in the second reference which shows the OS as Win11 it says “As you can see, in player.setOnError() the code allows to re-try opening the file, which does work. So a typical run starts the first movie without problem. For movie 2 it needs 1 re-try, movie 3 needed 7 re-trys, and movie 4 needed 3 re-trys. But I also have runs where the application needed to re-try the first movie and all others were fine. So technically each movie is "showable".” is exactly the behavior I see.

So is the only solution to find an old Win10 laptop just to run this application?

EDIT: I should say that the "flaky" issue with MediaView only relates to the playing of videos. The same application can use images in lieu of videos in the sequencer and that continues to work flawlessly, even after the Win 10 to Win11 update.
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Have you tried running with a later version of Java 21/23 maybe. From the post you linked, it appears it has been a known issue for a couple of years and may have been addressed in a later version, I did a quick search and couldn't find mention of it. You might want to check the release notes and see if it's there.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks @stevel05. Given where I'm at, I'll try anything. I just need to refresh my memory on where I download the later versions of Java from and how to include JavaFX into the folder structure because I usually just use the zip conveniently provided by @Erel.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I can't remember where I download the jdk's from now. Will have a search if you can't find them.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
This solution from aeric solve my media problem under API-34:
- v1.01 - (B4A) adds support for targetSdkVersion=34. New requirement in manifest editor:

API-34 Manifest addition for MCExample program (ExoPlayer, MediaChooser, SimpleMediaManager) :
SetServiceAttribute(KeepRunningService, android:foregroundServiceType, shortService)

And OpenJDK Downloads and JavaFX download.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Thank you @MicroDrie for your pointer to the OpenJDK and JavaFX downloads.

I've tried Java 21 in lieu of Java 19, but I did not see a noticeable improvement on either the desktop I do the app development on or the laptop used in the production environment, which is sometimes hard to assess given the random nature of the video media exception errors being thrown.

But some more research suggested to try disabling hardware acceleration and so I added:

B4X:
#VirtualMachineArgs: -Dprism.order=sw

to implement that in my standalone package.

Only time will tell if that's made any difference, but I'd like confirmation that by doing this, hardware acceleration is only disabled in my application and all other Windows applications will be unaffected by this change.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Only time will tell if that's made any difference, but I'd like confirmation that by doing this, hardware acceleration is only disabled in my application and all other Windows applications will be unaffected by this change.
A Java program runs in its own Virtual Machine (VM). If you want proof of isolation between them, you can of course first start the program with the modification and then a program without the problem modification for the ultimate proof in answer to your question.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Thank you @MicroDrie for your explanation, which confirms my understanding.

However in the production environment last night, error were thrown on the first 2 videos of a 10 video sequence and then on the second execution all 12 videos played without error. So it seems the idea of disabling hardware acceleration did not eliminate the random errors.

My next step is to find an old Win10 machine and run the app on that to confirm my theory that it is a Win11 related issue.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
There appears to have been no progress in addressing this reported JavaFX bug Video sometimes does not start when reinitializing in Windows 11 which I was hopeful may resolve the intermittent playing of videos in Mediaview after updating from Win10 to Win11 reported in Post #1.

However a new JavaFX "bug" has been reported involving Update GStreamer to 1.26.5 and given I understand Mediaview uses the GStreamer library, I am following this integration with interest in the hope that it may overcome my "problem". As soon as I'm aware there is an early release JavaFX 26 incorporating this update, I'll give it a try because ChatGPT tells me "Moving from 1.24.10 → 1.26.5 should make JavaFX media more stable and less crash-prone, especially for repeated playback".

Only time will tell, but I'd be interested in comments from Forum members knowledgeable in this area.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Just an update for those with an interest in this topic and pleasingly a positive one, if not a complete fix.

Despite being optimistic that the fix to JavaFX bug report JDK-8366217 Update GStreamer to 1.26.5 may resolve my problem of intermittent video failures in Mediaview after updating from Win10 to Win11 reported in Post #1, I was advised by those responsible that "JDK-8305842 is still reproducible on Windows 11 with JDK-8366217".

However when I enquired as to the progress in resolving JDK-8305842 Video sometimes does not start when reinitializing in Windows 11 I was advised "Yes, there was some work done on JDK-8305842. Root cause is known, but I did not had time to debug it and fix. If you have ability to convert videos to H.265/HEVC you can use it as a work around for this issue. So far there are no known issues with H.265."

Those following along may recall that as a result of discussion in this Forum thread jMediaView I tried various versions of H.264 codec without success and not being knowledgeable in the area of video formats/codecs, didn't even consider trying H.265.

Therefore I did a test today using my existing H.264/AVC videos where I triggered the video playing sequence in my application remotely via WiFi every 2 minutes and after 2 hours I had logged many failures to play of individual videos. I re-encoded the 13 relevant videos using Handbrake to H.265/AVEC and repeated the test.

To my delight, no errors have been logged and so at least until JDK-8305842 is resolved, I can return to using my application under Win11 by ensuring any videos are H.265/HEVC and given I have complete control over those videos, that’s not a problem.

I won't mark this thread as solved because this is just a work around and will wait to do that when JDK-8305842 is resolved and available in a JavaFX release.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…