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
Top