JMTC is a lightweight Java library that integrates a Java application with the Media Transport Controls and Now Playing elements of the operating System. The properties of the currently playing Media can easily be set and the library defines callbacks for the Media Keys(global) and the UI elements.
- Title, Artist, Album Title, Album Artist, Playtime and Cover Art fields supported
- Seeking, Play/Pause, Stop, Volume, Shuffle, Rate and Looping supported
- simple callback syntax via Lambda Functions
- easily integrable into projects using Compose Multiplatform, JavaFX, Swing, TornadoFX, etc.
- Logging
- graceful Error Handling
- Support for different Media Types (Video, Photo) ???
- Windows (via SystemMediaTransportControls)
- Linux (via MPRIS 2 on D-Bus)
- Mac (TODO currently I have no test system)
- Java 8 or later
TODO This Library is not yet available on a Maven repository.
Download this repository via git with:
git clone https://github.com/Selemba1000/JavaMediaTransportControls.git
or download as zip and extract it. Then load the project into your IDE of choice and execute Task publishToMavenLocal. Then add the following to your build.gradle:
repositories {
mavenLocal()
}
dependencies {
implementation 'io.github.selemba1000:jmtc:1.0.0'
}
To start with the Library first get an instance of JMTC:
JMTC jmtc = JMTC.getInstance(
new JMTCSettings("example-player-name","example-player-desktop-file")
);
Then you can set all parameters via this instance, for example:
JMTCCallbacks callbacks = new JMTCCallbacks();
callbacks.onPlay = () -> {
control.setPlayingState(JMTCPlayingState.PLAYING);
};
callbacks.onPause = () -> control.setPlayingState(JMTCPlayingState.PAUSED);
jmtc.setEnabledButtons(
new JMTCEnabledButtons(
true,
true,
true,
true,
true
)
);
jmtc.setCallbacks(callbacks);
jmtc.setEnabled(true);
jmtc.setMediaType(JMTCMediaType.Music);
jmtc.setPlayingState(JMTCPlayingState.PAUSED);
control.setMediaProperties(
new JMTCMusicProperties(
"TestTitle",
"TestArtist",
"test",
"tset",
new String[]{},
0,
1,
null
)
);
jmtc.setTimelineProperties(
new JMTCTimelineProperties(
0L,
100000L,
0L,
100000L
)
);
jmtc.setPlayingState(JMTCPlayingState.PLAYING);
jmtc.updateDisplay();
jmtc.setPosition(100L);
TODO