use of org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseHandler in project malp by gateship-one.
the class MPDQueryHandler method handleMessage.
/**
* This is the main entry point of messages.
* Here all possible messages types need to be handled with the MPDConnection.
* Have a look into the baseclass MPDGenericHandler for more information about the handling.
*
* @param msg Message to process.
*/
@Override
public void handleMessage(Message msg) {
// Call the baseclass handleMessage method here to ensure that the messages handled
// by the baseclass are handled in subclasses as well.
super.handleMessage(msg);
// Type checking
if (!(msg.obj instanceof MPDHandlerAction)) {
/* Check if the message object is of correct type. Otherwise just abort here. */
return;
}
MPDHandlerAction mpdAction = (MPDHandlerAction) msg.obj;
// ResponseHandler used to return the requested items to the caller
MPDResponseHandler responseHandler;
/*
* All messages are handled the same way:
* * Check which action was requested
* * Check if a ResponseHandler is necessary and also provided. (If not just abort here)
* * Request the list of data objects from the MPDConnection (and therefor from the server)
* * Pack the response in a Message requested from the given ResponseHandler.
* * Send the message to the ResponseHandler
*/
MPDHandlerAction.NET_HANDLER_ACTION action = mpdAction.getAction();
try {
if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUMS) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseAlbumList)) {
return;
}
List<MPDAlbum> albumList = MPDInterface.mInstance.getAlbums();
((MPDResponseAlbumList) responseHandler).sendAlbums(albumList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUMS_IN_PATH) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseAlbumList)) {
return;
}
String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
List<MPDAlbum> albumList = MPDInterface.mInstance.getAlbumsInPath(path);
((MPDResponseAlbumList) responseHandler).sendAlbums(albumList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ALBUMS_IN_PATH) {
String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
List<MPDAlbum> albumList = MPDInterface.mInstance.getAlbumsInPath(path);
MPDInterface.mInstance.clearPlaylist();
for (MPDAlbum album : albumList) {
MPDInterface.mInstance.addAlbumTracks(album.getName(), album.getArtistName(), album.getMBID());
}
MPDInterface.mInstance.playSongIndex(0);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTIST_ALBUMS) {
String artistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseAlbumList) || (null == artistName)) {
return;
}
List<MPDAlbum> albumList = MPDInterface.mInstance.getArtistAlbums(artistName);
((MPDResponseAlbumList) responseHandler).sendAlbums(albumList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTISTSORT_ALBUMS) {
String artistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseAlbumList) || (null == artistName)) {
return;
}
List<MPDAlbum> albumList = MPDInterface.mInstance.getArtistSortAlbums(artistName);
((MPDResponseAlbumList) responseHandler).sendAlbums(albumList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTISTS) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseArtistList)) {
return;
}
List<MPDArtist> artistList = MPDInterface.mInstance.getArtists();
((MPDResponseArtistList) responseHandler).sendArtists(artistList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTISTSORT) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseArtistList)) {
return;
}
List<MPDArtist> artistList = MPDInterface.mInstance.getArtistsSort();
((MPDResponseArtistList) responseHandler).sendArtists(artistList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUMARTISTS) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseArtistList)) {
return;
}
MPDCapabilities caps = MPDInterface.mInstance.getServerCapabilities();
List<MPDArtist> artistList;
// Check if server supports the right tag, otherwise use fallback list
if (null != caps && caps.hasTagAlbumArtist()) {
artistList = MPDInterface.mInstance.getAlbumArtists();
} else {
// If server does not support the albumartist tag
artistList = MPDInterface.mInstance.getArtists();
}
((MPDResponseArtistList) responseHandler).sendArtists(artistList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUMARTISTSORT) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseArtistList)) {
return;
}
MPDCapabilities caps = MPDInterface.mInstance.getServerCapabilities();
List<MPDArtist> artistList;
// Check if server supports the right tag, otherwise use fallback list
if (null != caps && caps.hasTagAlbumArtist()) {
artistList = MPDInterface.mInstance.getAlbumArtistsSort();
} else {
// If server does not support the albumartist tag
artistList = MPDInterface.mInstance.getArtistsSort();
}
((MPDResponseArtistList) responseHandler).sendArtists(artistList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ALBUM_TRACKS) {
String albumName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList) || (null == albumName)) {
return;
}
List<MPDFileEntry> trackList = MPDInterface.mInstance.getAlbumTracks(albumName, albumMBID);
((MPDResponseFileList) responseHandler).sendFileList(trackList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_TRACKS) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList)) {
return;
}
List<MPDFileEntry> trackList = MPDInterface.mInstance.getAllTracks();
((MPDResponseFileList) responseHandler).sendFileList(trackList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTIST_ALBUM_TRACKS) {
String artistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
String albumName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList) || (null == albumName) || (null == artistName)) {
return;
}
List<MPDFileEntry> trackList = MPDInterface.mInstance.getArtistAlbumTracks(albumName, artistName, albumMBID);
((MPDResponseFileList) responseHandler).sendFileList(trackList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_ARTIST_SORT_ALBUM_TRACKS) {
String artistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
String albumName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList) || (null == albumName) || (null == artistName)) {
return;
}
List<MPDFileEntry> trackList = MPDInterface.mInstance.getArtistSortAlbumTracks(albumName, artistName, albumMBID);
((MPDResponseFileList) responseHandler).sendFileList(trackList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_CURRENT_PLAYLIST) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList)) {
return;
}
List<MPDFileEntry> trackList = MPDInterface.mInstance.getCurrentPlaylist();
((MPDResponseFileList) responseHandler).sendFileList(trackList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_CURRENT_PLAYLIST_WINDOW) {
int start = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_WINDOW_START);
int end = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_WINDOW_END);
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList)) {
return;
}
List<MPDFileEntry> trackList = MPDInterface.mInstance.getCurrentPlaylistWindow(start, end);
((MPDResponseFileList) responseHandler).sendFileList(trackList, start, end);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_SAVED_PLAYLIST) {
String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList)) {
return;
}
List<MPDFileEntry> trackList = MPDInterface.mInstance.getSavedPlaylist(playlistName);
((MPDResponseFileList) responseHandler).sendFileList(trackList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_SAVED_PLAYLISTS) {
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList)) {
return;
}
List<MPDFileEntry> playlistList = MPDInterface.mInstance.getPlaylists();
((MPDResponseFileList) responseHandler).sendFileList(playlistList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_SAVE_PLAYLIST) {
String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
MPDInterface.mInstance.savePlaylist(playlistName);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_SONG_TO_PLAYLIST) {
String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
MPDInterface.mInstance.addSongToPlaylist(playlistName, path);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_REMOVE_SONG_FROM_PLAYLIST) {
String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
int position = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SONG_INDEX);
MPDInterface.mInstance.removeSongFromPlaylist(playlistName, position);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_REMOVE_PLAYLIST) {
String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
MPDInterface.mInstance.removePlaylist(playlistName);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_LOAD_PLAYLIST) {
String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
MPDInterface.mInstance.loadPlaylist(playlistName);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_PLAYLIST) {
String playlistName = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PLAYLIST_NAME);
MPDInterface.mInstance.clearPlaylist();
MPDInterface.mInstance.loadPlaylist(playlistName);
MPDInterface.mInstance.playSongIndex(0);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_ARTIST_ALBUM) {
String albumname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
MPDInterface.mInstance.addAlbumTracks(albumname, artistname, albumMBID);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_ARTIST_SORT_ALBUM) {
String albumname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
MPDInterface.mInstance.addArtistSortAlbumTracks(albumname, artistname, albumMBID);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ARTIST_ALBUM) {
String albumname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
MPDInterface.mInstance.clearPlaylist();
MPDInterface.mInstance.addAlbumTracks(albumname, artistname, albumMBID);
MPDInterface.mInstance.playSongIndex(0);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ARTIST_SORT_ALBUM) {
String albumname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_NAME);
String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
String albumMBID = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ALBUM_MBID);
MPDInterface.mInstance.clearPlaylist();
MPDInterface.mInstance.addArtistSortAlbumTracks(albumname, artistname, albumMBID);
MPDInterface.mInstance.playSongIndex(0);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_ARTIST) {
String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
MPDAlbum.MPD_ALBUM_SORT_ORDER sortOrder = MPDAlbum.MPD_ALBUM_SORT_ORDER.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SORT_ORDER)];
MPDInterface.mInstance.addArtist(artistname, sortOrder);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ARTIST) {
String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
MPDAlbum.MPD_ALBUM_SORT_ORDER sortOrder = MPDAlbum.MPD_ALBUM_SORT_ORDER.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SORT_ORDER)];
MPDInterface.mInstance.clearPlaylist();
MPDInterface.mInstance.addArtist(artistname, sortOrder);
MPDInterface.mInstance.playSongIndex(0);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_ARTIST_SORT) {
String artistname = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_ARTIST_NAME);
MPDAlbum.MPD_ALBUM_SORT_ORDER sortOrder = MPDAlbum.MPD_ALBUM_SORT_ORDER.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SORT_ORDER)];
MPDInterface.mInstance.clearPlaylist();
MPDInterface.mInstance.addArtistSort(artistname, sortOrder);
MPDInterface.mInstance.playSongIndex(0);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_PATH) {
String url = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SONG_URL);
MPDInterface.mInstance.addSong(url);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_SONG_NEXT) {
String url = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SONG_URL);
MPDCurrentStatus status = MPDInterface.mInstance.getCurrentServerStatus();
MPDInterface.mInstance.addSongatIndex(url, status.getCurrentSongIndex() + 1);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_SONG) {
String url = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SONG_URL);
MPDCapabilities caps = MPDInterface.mInstance.getServerCapabilities();
/*
* Check if song is already enqueued in the current playlist. If it is get the position
* and just jump to the song position.
*
* Otherwise add it to the last playlist position and jump there.
*/
List<MPDFileEntry> playlistFindTracks = null;
if (caps != null && caps.hasPlaylistFind()) {
playlistFindTracks = MPDInterface.mInstance.getPlaylistFindTrack(url);
}
if (playlistFindTracks != null && playlistFindTracks.size() > 0) {
// Song already found in the playlist. Jump there.
MPDInterface.mInstance.playSongIndex(((MPDTrack) playlistFindTracks.get(0)).getSongPosition());
} else {
// Not part of the current playlist. Add it at the end of the playlist and play it from there.
MPDInterface.mInstance.addSong(url);
MPDCurrentStatus status = MPDInterface.mInstance.getCurrentServerStatus();
MPDInterface.mInstance.playSongIndex(status.getPlaylistLength() - 1);
}
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_CLEAR_CURRENT_PLAYLIST) {
MPDInterface.mInstance.clearPlaylist();
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_SHUFFLE_CURRENT_PLAYLIST) {
MPDInterface.mInstance.shufflePlaylist();
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_MOVE_SONG_AFTER_CURRENT) {
MPDCurrentStatus status = MPDInterface.mInstance.getCurrentServerStatus();
int index = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SONG_INDEX);
if (index < status.getCurrentSongIndex()) {
MPDInterface.mInstance.moveSongFromTo(index, status.getCurrentSongIndex());
} else if (index > status.getCurrentSongIndex()) {
MPDInterface.mInstance.moveSongFromTo(index, status.getCurrentSongIndex() + 1);
}
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_REMOVE_SONG_FROM_CURRENT_PLAYLIST) {
int index = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SONG_INDEX);
MPDInterface.mInstance.removeIndex(index);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_REMOVE_RANGE_FROM_CURRENT_PLAYLIST) {
int start = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_WINDOW_START);
int end = mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_WINDOW_END);
MPDInterface.mInstance.removeRange(start, end);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_FILES) {
String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList)) {
return;
}
List<MPDFileEntry> fileList = MPDInterface.mInstance.getFiles(path);
((MPDResponseFileList) responseHandler).sendFileList(fileList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_DIRECTORY) {
String path = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
MPDInterface.mInstance.clearPlaylist();
MPDInterface.mInstance.addSong(path);
MPDInterface.mInstance.playSongIndex(0);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_OUTPUTS) {
responseHandler = mpdAction.getResponseHandler();
List<MPDOutput> outputList = MPDInterface.mInstance.getOutputs();
((MPDResponseOutputList) responseHandler).sendOutputs(outputList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_GET_SERVER_STATISTICS) {
responseHandler = mpdAction.getResponseHandler();
MPDStatistics stats;
stats = MPDInterface.mInstance.getServerStatistics();
((MPDResponseServerStatistics) responseHandler).sendServerStatistics(stats);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_UPDATE_DATABASE) {
String updatePath = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_PATH);
MPDInterface.mInstance.updateDatabase(updatePath);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_SEARCH_FILES) {
String term = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SEARCH_TERM);
MPDCommands.MPD_SEARCH_TYPE type = MPDCommands.MPD_SEARCH_TYPE.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SEARCH_TYPE)];
responseHandler = mpdAction.getResponseHandler();
if (!(responseHandler instanceof MPDResponseFileList)) {
return;
}
List<MPDFileEntry> fileList = MPDInterface.mInstance.getSearchedFiles(term, type);
((MPDResponseFileList) responseHandler).sendFileList(fileList);
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_ADD_SEARCH_FILES) {
String term = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SEARCH_TERM);
MPDCommands.MPD_SEARCH_TYPE type = MPDCommands.MPD_SEARCH_TYPE.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SEARCH_TYPE)];
MPDCapabilities caps = MPDInterface.mInstance.getServerCapabilities();
// Check if server has the add search result capability
if (null != caps && caps.hasSearchAdd()) {
MPDInterface.mInstance.addSearchedFiles(term, type);
} else {
// Fetch search results and add them
List<MPDFileEntry> searchResults = MPDInterface.mInstance.getSearchedFiles(term, type);
MPDInterface.mInstance.addTrackList(searchResults);
}
} else if (action == MPDHandlerAction.NET_HANDLER_ACTION.ACTION_PLAY_SEARCH_FILES) {
String term = mpdAction.getStringExtra(MPDHandlerAction.NET_HANDLER_EXTRA_STRING.EXTRA_SEARCH_TERM);
MPDCommands.MPD_SEARCH_TYPE type = MPDCommands.MPD_SEARCH_TYPE.values()[mpdAction.getIntExtra(MPDHandlerAction.NET_HANDLER_EXTRA_INT.EXTRA_SEARCH_TYPE)];
MPDInterface.mInstance.clearPlaylist();
// Check if server has the add search result capability
if (MPDInterface.mInstance.getServerCapabilities().hasSearchAdd()) {
MPDInterface.mInstance.addSearchedFiles(term, type);
} else {
// Fetch search results and add them
List<MPDFileEntry> searchResults = MPDInterface.mInstance.getSearchedFiles(term, type);
MPDInterface.mInstance.addTrackList(searchResults);
}
MPDInterface.mInstance.playSongIndex(0);
}
} catch (MPDException e) {
handleMPDError(e);
}
}
use of org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseHandler in project malp by gateship-one.
the class MPDStateMonitoringHandler method handleMessage.
/**
* This is the main entry point of messages.
* Here all possible messages types need to be handled with the MPDConnection.
*
* @param msg Message to process.
*/
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (!(msg.obj instanceof MPDHandlerAction)) {
/* Check if the message object is of correct type. Otherwise just abort here. */
return;
}
MPDHandlerAction mpdAction = (MPDHandlerAction) msg.obj;
/* Catch MPD exceptions here for now. */
MPDResponseHandler responseHandler;
MPDHandlerAction.NET_HANDLER_ACTION action = mpdAction.getAction();
}
Aggregations