This library includes the complete Karafun Player API.
Dependencies:
- OKHttp: for WebSocket
- Apache-Common-Lang3: for escaping XML
Create a KarafunListener by implementing that interface:
public class SimpleKarafunListener implements KarafunListener {
@Override
public void onPlayerStatus(Status status) {
}
@Override
public void onCatalogList(CatalogList list) {
}
@Override
public void onList(SongList list) {
}
@Override
public void onConnected() {
}
@Override
public void onDisconnected() {
}
}
Then create a new client with:
KarafunListener listener = new SimpleKarafunListener();
KarafunClient client =
new KarafunClient().connect("ws://someAddress:57570");
client.setListener(listener);
Now getting status shouldn't be a problem:
client.getStatus();
Now the onPlayerStatus
should be called with the response from the server.
Default constructor:
public KarafunClient();
Constructor with socket injection:
public KarafunClient(Socket socket);
Connect to server. Provide a websocket URL:
public void connect(String url);
Close the WebSocket connection:
public void close();
Get the current listener:
public KarafunListener getListener();
Set the listener:
public void setListener(KarafunListener listener);
Sends a getStatus request:
public void getStatus();
Sends a getStatus request without queue, if noQueue
is set to true
:
public void getStatus(boolean noQueue);
Sends a getCatalogList, request:
public void getCatalogList();
Sends a getList request, given the ID of the list, and the offset and limit:
public void getList(int id, int offset, int limit);
Sends a search request, given a offset, limit, and a search string:
public void search(int offset, int limit, String searchString);
Requests for audio control and transport:
public void play();
public void pause();
public void next();
public void seek(int timeInSeconds);
public void pitch(int pitch);
public void tempo(int tempo);
Sends a setVolume request, given the volume type, and volume:
public void setVolume(VolumeType type, int volume);
Requests for song queue management:
public void clearQueue();
public void addToQueue(int songId, String singerName, int position);
public void removeFromQueue(int queuePosition);
public void changeQueuePosition(int oldPosition, int newPosition);
Complete Karafun Player API documentation: http://www.karafun.com/developers/karafun-player-api.html