Simple Java Library for getting information about the current playback from the windows system media transport controls (SMTC).
- Java 21 or later
- Windows 10 or later
- GSON library for JSON parsing
Load the native library
SMTC4J.load();long updateIntervalMillis = 500; // e.g., update every 500ms
SMTC4J.startUpdateScheduler(updateIntervalMillis);Media info (title, artist, album, duration, cover, source app):
MediaInfo mediaInfo = SMTC4J.getCachedMediaInfo();
System.out.println("Title: " + mediaInfo.getTitle());Playback state (play/pause/stop code, position in seconds):
PlaybackState playbackState = SMTC4J.getCachedPlaybackState();
System.out.println("State code: " + playbackState.getStateCode());
System.out.println("Position: " + playbackState.getPosition());Using the scheduler:
SMTC4J.scheduleKeyPress(MediaKey.PLAY);Or directly:
SMTC4J.pressKey(MediaKey.NEXT);This only works on Windows 10 and later versions, as it relies on the Windows SMTC API.
The the jars in the releases are built for x64 architecture.
If you you really need x86 support, you can build the native library from source using the provided C++ code.
If you try to call the native methods on a thread on which COM is already initialized, it may lead to crashes.
To avoid this, you should use the provided scheduler methods which handle threading and COM initialization internally.