You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rainer Hihn 31d95c913e M src/main/java/org/bff/javampd/server/Mpd.java 3 months ago
.github Create dependabot.yml 3 months ago
src M src/main/java/org/bff/javampd/server/Mpd.java 3 months ago
.gitignore init 3 months ago
LICENSE.txt init 3 months ago
README.md Update README.md 3 months ago
pom.xml Set license to GPL2 (according to LICENSE.txt) 3 months ago

README.md

JavaMPD


This is a fork of finnyb/javampd


JavaMPD is used by java clients to control the cool MPD.

Download

<dependency>
  <groupId>org.hihn</groupId>
  <artifactId>javampd</artifactId>
  <version>6.1.14</version>
</dependency>

Javadocs

Javadocs

Using

Create a connection to MPD using the builder.

Using default values of localhost port 6600

MPD mpd = new MPD.Builder().build();

or build to your environment

MPD mpd = new MPD.Builder()
        .server("yourserver")
        .port(yourport)
        .password(yourpassword)
        .build();

Almost everything you’ll need will be gotten from this object.

The connection remains open for the life of the MPD object so take care not to create new MPD objects each time you want to do something. Call close on the object when you are done.

Art

When running on the same server as MPD a list of artwork can be obtained for an artist or album. If not running on the same server but hosting the images locally a path prefix can be passed to locate the images.

A list of all images in the directory can be returned if those files are readable by whatever user is running JavaMPD.

Ideally you should have some directory structure like /Artist/Album/song.flac /Artist/Album/cover.jpg

When searching for artist images assumptions are made that the artist lives in her own directory. Images in the artist directory are returned first then images for each album are returned.

supported image types: jpg and png

ArtworkFinder artworkFinder = mpd.getArtworkFinder();
List<MPDArtwork> artworkList = artworkFinder.find(album);

Searching

Searching for songs is done via the SongSearcher class.

mpd.getSongSearcher();

Querying

MPD database access is accomplished using the appropriate access object from the MPDMusicDatabase.

Get the database from MPD.

mpd.getMusicDatabase();

There is a database for the following:

  • Songs
  • Albums
  • Artists
  • Genres
  • Years
  • Playlists
  • Files

Logging

slf4j is used for logging allowing you to use any compatible logging framework. The following examples use logback.

Lots of debugging information can be obtained from debug level logging.

...
<root level="debug">
    <appender-ref ref="STDOUT"/>
</root>
...

Monitoring

MPDStandAloneMonitor to monitor events

Refresh Intervals

The monitor.delay property is the length of time (in seconds) that the monitor sleeps between rounds. Each monitor has a multiplier that can be overridden depending on the desired check frequency. Setting the multiplier value to 0 means checking every time the monitor runs (0 based).

The following properties can be overridden:

monitor.delay

monitor.output.multiplier
monitor.connection.multiplier
monitor.playlist.multiplier
monitor.error.multiplier
monitor.player.multiplier
monitor.track.multiplier
monitor.exception.multiplier

To override place a javampd.properties file on the classpath with your desired overrides:

For example:

javampd.properties

monitor.playlist.multiplier=4

would check for playlist changes every ~5 seconds

or maybe something list this:

javampd.properties

monitor.delay=10
monitor.playlist.multiplier=0
monitor.track.multiplier=2

would run the monitor every ~10 seconds checking the playlist every ~10 seconds and the track every ~30

Server status

load the server status by getting the status from MPD.

ServerStatus status = mpd.getServerStatus();
int volume = status.getVolume();

There is a default expiry interval of 5 seconds. This can be overridden by setting the interval using setExpiryInterval, use 0 to always call the server for each method.

ServerStatus status = mpd.getServerStatus();
//removes 5 second cache
status.setExpiryInterval(0);    

Status updates can be force using forceUpdate

ServerStatus status = mpd.getServerStatus();
//reset the update clock so updates are pulled
status.forceUpdate();

Server statistics

load the server statistics by getting the status from MPD.

ServerStatistics stats = mpd.getServerStatistics();
long uptime = status.getUptime();

It has an default expiry interval of 60 seconds. Caching behavior is exactly like the status.