B4J Question Simple Media Manager

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All, I am trying to use Simple Media Manager as recommended by @stevel05

I manage to run the code but there is no Video on the screen. It runs streaming video with no problem. I want to switch between Video and JPG's

Here is the code I have tried

Code:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Pane3 As B4XView
    Private MediaManager As SimpleMediaManager
End Sub

Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    MediaManager.Initialize
    Dim extra As Map = CreateMap(MediaManager.REQUEST_ROUNDIMAGE: False, MediaManager.REQUEST_BACKGROUND: xui.Color_Yellow)
    MediaManager.SetMediaFromFile(Pane3, File.DirAssets, "ftest.mp4", "video/mp4",extra )

End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    MediaManager.PanelResized(Pane3)
End Sub

I have done the setting

1768420333026.png

Here is the error

Waiting for debugger to connect...
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.NullPointerException
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:458)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
... 5 more
java.lang.ExceptionInInitializerError
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.loadClass(LauncherImpl.java:382)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$3(LauncherImpl.java:421)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: java.net.SocketException: Connection reset
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at b4j.video.main.<clinit>(main.java:17)
... 12 more
Caused by: java.net.SocketException: Connection reset
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:271)
at java.base/java.io.DataInputStream.readByte(DataInputStream.java:270)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
... 14 more

changing the Video type to video/* gives me this result





There must be something i am doing wrong. Please help if you know how to solve it.

Thank you
 
Last edited:
Solution
Hi All, I am trying to use Simple Media Manager as recommended by @stevel05

I manage to run the code but there is no Video on the screen. It runs streaming video with no problem. I want to switch between Video and JPG's

Here is the code I have tried

Code:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Pane3 As B4XView
    Private MediaManager As SimpleMediaManager
End Sub

Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    MediaManager.Initialize
    Dim extra As Map =...

AnandGupta

Expert
Licensed User
Longtime User
You may need the "SMM_VIDEO" compile symbol
check
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
You may need the "SMM_VIDEO" compile symbol
check
I did put a picture of that incase someone though we might need it , was one of the first things done
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Hi All, I am trying to use Simple Media Manager as recommended by @stevel05

I manage to run the code but there is no Video on the screen. It runs streaming video with no problem. I want to switch between Video and JPG's

Here is the code I have tried

Code:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Pane3 As B4XView
    Private MediaManager As SimpleMediaManager
End Sub

Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    MediaManager.Initialize
    Dim extra As Map = CreateMap(MediaManager.REQUEST_ROUNDIMAGE: False, MediaManager.REQUEST_BACKGROUND: xui.Color_Yellow)
    MediaManager.SetMediaFromFile(Pane3, File.DirAssets, "ftest.mp4", "video/mp4",extra )

End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    MediaManager.PanelResized(Pane3)
End Sub

I have done the setting



Here is the error



changing the Video type to video/* gives me this result






There must be something i am doing wrong. Please help if you know how to solve it.

Thank you
Your code works.
JavaFx does not support all MP4 encoding types.
Try to convert the encoding of the ftest.mp4 to H.264, or download the dizzy.mp4 for your testing
 
Upvote 2
Solution

Peter Lewis

Active Member
Licensed User
Longtime User
Your code works.
JavaFx does not support all MP4 encoding types.
Try to convert the encoding of the ftest.mp4 to H.264, or download the dizzy.mp4 for your testing
Thank you , the Dizzy works. Is there b4x code to convert to H.264 ? Do you know of a way to get rid of the seek bar, volume and all controls as well as auto starting the video.

I want to fill the Pane with the video with no extra options
1768494772843.png


Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
note:

As you correctly noted, Oracle no longer includes JavaFX in the standard JDK. It is now maintained as OpenJFX, an open-source project led by Gluon and the community.
In 2026, the javafx.media module has evolved to support modern standards while removing legacy formats. Here are the codecs and updates available as of early 2026:

1. New & Updated Codec Support
  • H.265 (HEVC): This is the most significant addition. JavaFX now supports H.265/HEVC video playback, which offers superior compression compared to H.264. It is particularly useful for high-resolution content and modern HTTP Live Streaming (HLS) delivery.
  • fMP4 (Fragmented MP4): Support for fragmented MP4 containers has been stabilized. This allows JavaFX to handle modern streaming formats used by major platforms, improving compatibility with HLS.
  • Apple Silicon & Metal: On macOS, the media pipeline has been optimized for Apple Silicon (M1/M2/M3/M4) chips. The rendering now integrates better with the Metal framework for smoother hardware-accelerated decoding.

2. Supported Formats in 2026
The current stable stack for JavaFX Media includes:
  • Video: H.264 (AVC) and H.265 (HEVC).
  • Audio: AAC (Advanced Audio Coding) and MP3.
  • Containers: MP4, MOV, and MPEG-TS.
  • Protocols: HTTP, HTTPS, and HLS (including multi-language audio tracks and fMP4 support).

3. Removed/Deprecated Formats
To maintain security and reduce the library's footprint, several legacy technologies have been completely removed:
  • VP6 & FLV: Flash Video (FLV) and the VP6 video codec are no longer supported.
  • Old GStreamer Layers: Older versions of the GStreamer library (the internal engine for JavaFX Media) have been phased out in favor of the 1.2x series.

4. How to Implement in 2026
Since it is an external library, you must include the dependency in your pom.xml (Maven) or build.gradle (Gradle).
Maven Dependency:

xml
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>23</version> <!-- Current stable version as of 2026 -->
<classifier>win</classifier> <!-- or mac / linux -->
</dependency>

Usa el código con precaución.

Summary of Change
The shift from Oracle to OpenJFX has actually accelerated media updates. By decoupling from the JDK, the JavaFX team can update the internal GStreamer engine more frequently, ensuring that JavaFX apps can run H.264 and H.265 video smoothly on Windows 11, macOS, and modern Linux distros.
 
Upvote 0
Top