Is there any way to play subtitles in JMF. Any source which I can read to proceed ?

Dani AI

Generated

Short answer: JMF itself has no built‑in subtitle/closed‑caption track support. That is why dragging an SRT into a simple JMF player does nothing. As and noted, the usual practical options are to render text yourself (overlay) or replace JMF with a player that already supports subtitles.

A reliable, low‑effort approach that works with existing JMF code is:

  • Parse the SRT/SubRip file into a list of {startMs, endMs, text}.
  • Put the JMF visual Component in a Swing container (JLayeredPane or similar) and overlay a transparent, non‑opaque JLabel for subtitles.
  • Use a javax.swing.Timer (100ms) that reads the current media time from the JMF Player (player.getMediaTime() -> seconds -> ms), looks up the active SRT entry, and updates the JLabel on the EDT.
  • Listen for player state/seek events via a ControllerListener and update the subtitle label immediately when the user seeks or when playback is paused/stopped.

Example sketch (concept only):

List<SrtEntry> subs = parseSrt("file.srt");
// every 100ms:
long nowMs = (long)(player.getMediaTime().getSeconds()*1000);
SrtEntry e = findEntryForTime(subs, nowMs);
SwingUtilities.invokeLater(() -> subtitleLabel.setText(e == null ? "" : e.text));

Caveats and tips:

  • Some JMF renderers are heavyweight/native; layering Swing components over them can fail. Use JLayeredPane and ensure the subtitle component is lightweight and non‑opaque, or use a separate transparent window positioned over the video.
  • Update on seek/realize events so subtitles stay in sync after scrubbing.
  • JMF is old and unmaintained; for modern, robust subtitle handling consider switching to bindings that support libVLC or GStreamer (they support embedded and external subtitle files out of the box).

References: JMF status and limitations, SRT format, and alternative libraries:

Recommended Answers

All 3 Replies

The most common way to show subtitles is to provide plain text file with time for start and end time showing subtitles followed by text for subtitle. For example if you use VLC media player it does allow you to select movie from hard drive and also in same time specify which other file to use with it for subtitles

you could use a transparent frame as i can remember. Strange that you are still using JMF :S

Thanks. But I meant if there is any inbuilt facility in JMF to play such subtitle files. Drag and drop of subtitles don't seem to work with videos when they are played using a simple JMF-based player.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.