use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry in project malp by gateship-one.
the class ArtworkManager method bulkLoadImages.
/**
* Entrance point to start downloading all images for the complete database of the current
* default MPD server.
*
* @param progressCallback Used callback interface to be notified about the download progress.
*/
public void bulkLoadImages(BulkLoadingProgressCallback progressCallback) {
if (progressCallback == null) {
return;
}
mBulkProgressCallback = progressCallback;
mArtistList.clear();
mAlbumList.clear();
mBulkLoadAlbumsReady = false;
mBulkLoadArtistsReady = false;
Log.v(TAG, "Start bulk loading");
if (HTTPAlbumImageProvider.getInstance(mContext).getActive()) {
Log.v(TAG, "Try to get all tracks from MPD");
MPDQueryHandler.getAllTracks(new MPDResponseFileList() {
@Override
public void handleTracks(List<MPDFileEntry> fileList, int windowstart, int windowend) {
Log.v(TAG, "Received track count: " + fileList.size());
new ParseMPDTrackListTask().execute(fileList);
}
});
} else {
if (!mAlbumProvider.equals(mContext.getString((R.string.pref_artwork_provider_none_key)))) {
MPDQueryHandler.getAlbums(new MPDResponseAlbumList() {
@Override
public void handleAlbums(List<MPDAlbum> albumList) {
new ParseMPDAlbumListTask().execute(albumList);
}
});
}
}
if (!mArtistProvider.equals(mContext.getString((R.string.pref_artwork_provider_none_key)))) {
MPDQueryHandler.getArtists(new MPDResponseArtistList() {
@Override
public void handleArtists(List<MPDArtist> artistList) {
new ParseMPDArtistListTask().execute(artistList);
}
});
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry in project malp by gateship-one.
the class FileAdapter method getView.
/**
* Create the actual listview items if no reusable object is provided.
*
* @param position Index of the item to create.
* @param convertView If != null this view can be reused to optimize performance.
* @param parent Parent of the view
* @return
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get MPDTrack at the given index used for this item.
MPDFileEntry file = (MPDFileEntry) getItem(position);
if (file instanceof MPDTrack) {
MPDTrack track = (MPDTrack) file;
// Normal file entry
if (!mShowSectionItems || (VIEW_TYPES.values()[getItemViewType(position)] == VIEW_TYPES.TYPE_FILE_ITEM)) {
if (convertView == null) {
convertView = new FileListItem(mContext, mShowIcons);
}
((FileListItem) convertView).setTrack(track, mUseTags, mContext);
if (!mShowTrackNumbers) {
((FileListItem) convertView).setTrackNumber(String.valueOf(position + 1));
}
return convertView;
} else {
// Section items
if (convertView == null) {
// If not create a new Listitem
convertView = new FileListItem(mContext, track.getTrackAlbum(), mShowIcons, this);
}
FileListItem tracksListViewItem = (FileListItem) convertView;
tracksListViewItem.setSectionHeader(track.getTrackAlbum());
tracksListViewItem.setTrack(track, mUseTags, mContext);
if (!mShowTrackNumbers) {
tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
}
// This will prepare the view for fetching the image from the internet if not already saved in local database.
// Dummy MPDAlbum
MPDAlbum tmpAlbum = new MPDAlbum(track.getTrackAlbum());
tmpAlbum.setMBID(track.getTrackAlbumMBID());
((FileListItem) convertView).prepareArtworkFetching(ArtworkManager.getInstance(mContext.getApplicationContext()), tmpAlbum);
// starts the loading.
if (mScrollSpeed == 0) {
((FileListItem) convertView).startCoverImageTask();
}
return convertView;
}
} else if (file instanceof MPDDirectory) {
if (convertView == null) {
convertView = new FileListItem(mContext, mShowIcons);
}
((FileListItem) convertView).setDirectory((MPDDirectory) file, mContext);
return convertView;
} else if (file instanceof MPDPlaylist) {
if (convertView == null) {
convertView = new FileListItem(mContext, mShowIcons);
}
((FileListItem) convertView).setPlaylist((MPDPlaylist) file, mContext);
return convertView;
}
return new FileListItem(mContext, mShowIcons);
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry in project malp by gateship-one.
the class FilesFragment method onItemClick.
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
mLastPosition = position;
MPDFileEntry file = (MPDFileEntry) mAdapter.getItem(position);
if (file instanceof MPDDirectory) {
mCallback.openPath(file.getPath());
} else if (file instanceof MPDPlaylist) {
mPlaylistCallback.openPlaylist(file.getPath());
} else if (file instanceof MPDTrack) {
switch(mClickAction) {
case ACTION_SHOW_DETAILS:
{
// Open song details dialog
SongDetailsDialog songDetailsDialog = new SongDetailsDialog();
Bundle args = new Bundle();
args.putParcelable(SongDetailsDialog.EXTRA_FILE, (MPDTrack) mAdapter.getItem(position));
songDetailsDialog.setArguments(args);
songDetailsDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "SongDetails");
return;
}
case ACTION_ADD_SONG:
{
MPDTrack track = (MPDTrack) mAdapter.getItem(position);
MPDQueryHandler.addPath(track.getPath());
return;
}
case ACTION_PLAY_SONG:
{
MPDTrack track = (MPDTrack) mAdapter.getItem(position);
MPDQueryHandler.playSong(track.getPath());
return;
}
case ACTION_PLAY_SONG_NEXT:
{
MPDTrack track = (MPDTrack) mAdapter.getItem(position);
MPDQueryHandler.playSongNext(track.getPath());
return;
}
}
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry 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.mpdprotocol.mpdobjects.MPDFileEntry in project malp by gateship-one.
the class MPDInterface method getCurrentSong.
/**
* This will query the current song playing on the mpd server.
*
* @return MPDTrack entry for the song playing.
*/
public synchronized MPDTrack getCurrentSong() throws MPDException {
mConnection.sendMPDCommand(MPDCommands.MPD_COMMAND_GET_CURRENT_SONG);
// Reuse the parsing function for tracks here.
List<MPDFileEntry> retList;
retList = MPDResponseParser.parseMPDTracks(mConnection);
if (retList.size() == 1) {
MPDFileEntry tmpFileEntry = retList.get(0);
if (null != tmpFileEntry && tmpFileEntry instanceof MPDTrack) {
return (MPDTrack) tmpFileEntry;
}
return null;
} else {
return null;
}
}
Aggregations