|3 months ago|
|.github||3 months ago|
|src||3 months ago|
|.gitignore||3 months ago|
|LICENSE.txt||3 months ago|
|README.md||3 months ago|
|pom.xml||3 months ago|
This is a fork of finnyb/javampd
JavaMPD is used by java clients to control the cool MPD.
<dependency> <groupId>org.hihn</groupId> <artifactId>javampd</artifactId> <version>6.1.14</version> </dependency>
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.
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 for songs is done via the SongSearcher class.
MPD database access is accomplished using the appropriate access object from the MPDMusicDatabase.
Get the database from MPD.
There is a database for the following:
Lots of debugging information can be obtained from debug level logging.
... <root level="debug"> <appender-ref ref="STDOUT"/> </root> ...
MPDStandAloneMonitor to monitor events
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:
would check for playlist changes every ~5 seconds
or maybe something list this:
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
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();
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.