Skip to content

Commit

Permalink
Publish V0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Selemba1000 committed Apr 19, 2024
1 parent 887751c commit 0133786
Show file tree
Hide file tree
Showing 21 changed files with 243 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ repositories {
mavenCentral()
}
dependencies{
implementation("io.github.selemba1000:JavaMediaTranportControls:0.0.1")
implementation("io.github.selemba1000:JavaMediaTranportControls:0.0.2")
}
```
Current version is 0.0.1.
Current version is 0.0.2.
#### Maven Local
Download this repository via git with:
```bash
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/github/selemba1000/JMTC.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
import io.github.selemba1000.linux.LinuxJMTC;
import io.github.selemba1000.windows.WindowsJMTC;

/**
* This singleton is the entrypoint to the library. Use getInstance to access the functions of the library
*/
public abstract class JMTC {

/**
* Instance reference to implement singleton pattern
*/
protected static JMTC INSTANCE;

/**
* Internal constructor to implement singleton pattern.
*/
protected JMTC() {
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/github/selemba1000/JMTCButtonCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

/**
* Interface for callback function for Buttons.
* Can be set as Lambda function.
*/
public interface JMTCButtonCallback {
/**
* Callback function.
*/
void callback();
}
6 changes: 6 additions & 0 deletions src/main/java/io/github/selemba1000/JMTCCallbacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*/
@SuppressWarnings("CanBeFinal")
public class JMTCCallbacks {
/**
* Creates an empty instance to be filled by property access
*/
public JMTCCallbacks() {
}

/**
* Callback for when Play button is pressed in UI or as MediaKey.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/github/selemba1000/JMTCMediaProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
* Abstract class for media properties. Not in Use currently.
*/
public abstract class JMTCMediaProperties {
/**
* Create empty instance. Not used directly as class is abstract.
*/
public JMTCMediaProperties(){}
}
3 changes: 3 additions & 0 deletions src/main/java/io/github/selemba1000/JMTCMediaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
* Currently only Music is supported.
*/
public enum JMTCMediaType {
/**
* Currently the only supported media type
*/
Music,
}
9 changes: 9 additions & 0 deletions src/main/java/io/github/selemba1000/JMTCParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ public JMTCParameters(LoopStatus loopStatus, Double volume, Double rate, Boolean
* Track = Loop current Track
*/
public enum LoopStatus {
/**
* Repeat nothing. Stop after last Song
*/
None,
/**
* Repeat the Playlist after the last song
*/
Playlist,
/**
* Repeat only the currently playing track
*/
Track
}
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/io/github/selemba1000/JMTCPlayingState.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@
* Changing = the player is changing the file. Windows only
*/
public enum JMTCPlayingState {
/**
* Media is currently playing
*/
PLAYING,
/**
* Media is currently paused
*/
PAUSED,
/**
* Media is stopped. Usually when media was selected, but not started.
*/
STOPPED,
/**
* Currently no media loaded.
*/
CLOSED,
/**
* The Media is currently changing/loading.
*/
CHANGING,

}
4 changes: 4 additions & 0 deletions src/main/java/io/github/selemba1000/JMTCSeekCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
* Interface for seek lambda callback.
*/
public interface JMTCSeekCallback {
/**
* The callback function.
* @param position The position that was seeked to in ms.
*/
void callback(Long position);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

/**
* Interface for callback when value of property changes.
* @param <T> the Type of value that changed
*/
public interface JMTCValueChangedCallback<T> {

/**
* Callback for when property changes
* @param property the property that changed
*/
void callback(T property);

}
14 changes: 14 additions & 0 deletions src/main/java/io/github/selemba1000/linux/LinuxJMTC.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.Map;
import java.util.Objects;

/**
* Central class for all Linux related interfacing.
*/
public class LinuxJMTC extends JMTC implements MPRISPlayer2, MPRISPlayer2Player, Properties {

private static final String generalInterface = "org.mpris.MediaPlayer2";
Expand Down Expand Up @@ -65,13 +68,24 @@ public class LinuxJMTC extends JMTC implements MPRISPlayer2, MPRISPlayer2Player,
final SignaledDBusProperty<Boolean> CanSeek = new SignaledDBusProperty<>(true, "CanSeek", getObjectPath(), playerInterface);
@SuppressWarnings("unused")
final DBusProperty<Boolean> CanControl = new DBusProperty<>(true, "CanControl");
/**
* Internal reference to all callbacks.
*/
protected JMTCCallbacks callbacks;
/**
* Internal reference to the dbus connection.
*/
private DBusConnection connection;

private Boolean enabled = false;

private String playerName;

/**
* Constructor to set up JMTC for Linux
* @param playerName a unique name for this instance
* @param desktopFile the desktop file of the app without the extension
*/
public LinuxJMTC(String playerName, String desktopFile) {
try {
this.playerName = playerName;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/github/selemba1000/linux/MPRISPlayer2.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.freedesktop.dbus.annotations.DBusProperty.Access;
import org.freedesktop.dbus.interfaces.DBusInterface;

/**
* Representation for the MPRIS2 MadiaPlayer DBus Interface
*/
@DBusInterfaceName("org.mpris.MediaPlayer2")
@DBusProperty(name = "Identity", type = String.class, access = Access.READ)
@DBusProperty(name = "DesktopEntry", type = String.class, access = Access.READ)
Expand All @@ -17,8 +20,14 @@
@DBusProperty(name = "CanRaise", type = Boolean.class, access = Access.READ)
public interface MPRISPlayer2 extends DBusInterface {

/**
* Request to raise the program to the foreground.
*/
void Raise();

/**
* Request to quit the program.
*/
void Quit();

}
79 changes: 79 additions & 0 deletions src/main/java/io/github/selemba1000/linux/MPRISPlayer2Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

import java.util.Map;

/**
* DBus reference for MPRIS Player
*/
@DBusInterfaceName("org.mpris.MediaPlayer2.Player")
@DBusProperty(name = "Metadata", type = Map.class, access = Access.READ)
@DBusProperty(name = "PlaybackStatus", type = String.class, access = Access.READ)
Expand All @@ -27,43 +30,102 @@
@DBusProperty(name = "CanSeek", type = Boolean.class, access = Access.READ)
public interface MPRISPlayer2Player extends DBusInterface {

/**
* Skip to the track before the currently playing one.
*/
@SuppressWarnings("unused")
void Previous();

/**
* Skip to the Song after the currently playing one.
*/
@SuppressWarnings("unused")
void Next();

/**
* Stop playback.
*/
@SuppressWarnings("unused")
void Stop();

/**
* Start playback.
*/
@SuppressWarnings("unused")
void Play();

/**
* Pause playback.
*/
@SuppressWarnings("unused")
void Pause();

/**
* Start and stop playback. Stop if currently playing. Start if currently paused.
*/
@SuppressWarnings("unused")
void PlayPause();

/**
* Seek to specified position.
*
* @param _arg0 position to seek to
*/
@SuppressWarnings("unused")
void Seek(long _arg0);

/**
* Open and play the specified uri.
*
* @param _arg0 The uri to play
*/
@SuppressWarnings("unused")
void OpenUri(String _arg0);

/**
* Jump to the specified Position in the specified song.
*
* @param _arg0 Song specified by path
* @param _arg1 Position to jump to
*/
@SuppressWarnings("unused")
void SetPosition(DBusPath _arg0, long _arg1);

/**
* Enum for the Loop status conversions.
*/
enum LoopStatus {
/**
* No repeating.
*/
None("None"),
/**
* Repeat the current Track.
*/
Track("Track"),
/**
* Repeat the current playlist
*/
Playlist("Playlist");

/**
* THe string representation of the status.
*/
public final String value;

/**
* Set a loop status via string representation
* @param value
*/
LoopStatus(String value) {
this.value = value;
}

/**
* Convert generalised status to linux specific version.
* @param status The general status to be converted
* @return The corresponding linux status
*/
static LoopStatus fromInner(JMTCParameters.LoopStatus status) {
switch (status) {
case None:
Expand All @@ -77,6 +139,10 @@ static LoopStatus fromInner(JMTCParameters.LoopStatus status) {
}
}

/**
* Convert this status to the generalised version.
* @return Generalised status
*/
JMTCParameters.LoopStatus toOuter() {
switch (this) {
case None:
Expand All @@ -91,15 +157,28 @@ JMTCParameters.LoopStatus toOuter() {

}

/**
* The DBusSignal emitted by using the seek feature.
*/
@SuppressWarnings("unused")
class Seeked extends DBusSignal {
private final long timeInUs;

/**
* THe constructor to create the Seeked signal,
* @param _path the path to the relevant track
* @param _timeInUs the time in us to seek
* @throws DBusException if DBus is not working properly
*/
public Seeked(String _path, long _timeInUs) throws DBusException {
super(_path);
timeInUs = _timeInUs;
}

/**
* Getter for the seeked time.
* @return The seeked TIme
*/
public long getTimeInUs() {
return timeInUs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
import com.sun.jna.Callback;
import io.github.selemba1000.JMTCButtonCallback;

/**
* Interface for callbacks executed by ButtonPresses
*/
public class ButtonPressedCallback implements Callback {

/**
* Callback delegate to avoid empty callbacks
*/
private final JMTCButtonCallback callbackDel;

/**
* Constructor to set the callback
* @param callback Callback to be set
*/
protected ButtonPressedCallback(JMTCButtonCallback callback) {
this.callbackDel = callback;
}

/**
* The Callback
*/
@SuppressWarnings("unused")
public void callback() {
if (callbackDel != null) {
Expand Down

0 comments on commit 0133786

Please sign in to comment.