use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus in project malp by gateship-one.
the class MPDStateMonitoringHandler method interpolateState.
private void interpolateState() {
// Generate a new dummy state
if (null != mLastStatus) {
MPDCurrentStatus status = new MPDCurrentStatus(mLastStatus);
long timeDiff = (System.nanoTime() - mLastTimeBase) / (1000 * 1000 * 1000);
// FIXME move timestamp to MPDConnection and MPDCurrentStatus (more precise, less time until saved)
status.setElapsedTime(mLastStatus.getElapsedTime() + (int) timeDiff);
distributeNewStatus(status);
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus in project malp by gateship-one.
the class MPDInterface method seekSeconds.
/**
* Seeks the currently playing song to a certain position
*
* @param seconds Position in seconds to which a seek is requested to.
*/
public synchronized void seekSeconds(int seconds) throws MPDException {
if (mConnection.getServerCapabilities().hasSeekCurrent()) {
mConnection.sendSimpleMPDCommand(MPDCommands.MPD_COMMAND_SEEK_CURRENT_SECONDS(seconds));
} else {
MPDCurrentStatus status;
status = getCurrentServerStatus();
mConnection.sendSimpleMPDCommand(MPDCommands.MPD_COMMAND_SEEK_SECONDS(status.getCurrentSongIndex(), seconds));
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus in project malp by gateship-one.
the class WidgetProvider method onReceive.
/**
* This is the broadcast receiver for NowPlayingInformation objects sent by the PBS
*
* @param context Context used for this receiver
* @param intent Intent containing the NowPlayingInformation as a payload.
*/
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
// Type checks
if (intent.getAction().equals(BackgroundService.ACTION_STATUS_CHANGED)) {
// Extract the payload from the intent
MPDCurrentStatus status = intent.getParcelableExtra(BackgroundService.INTENT_EXTRA_STATUS);
// Check if a payload was sent
if (null != status) {
// Save the information for later usage (when the asynchronous bitmap loader finishes)
mLastStatus = status;
}
} else if (intent.getAction().equals(BackgroundService.ACTION_TRACK_CHANGED)) {
// Extract the payload from the intent
MPDTrack track = intent.getParcelableExtra(BackgroundService.INTENT_EXTRA_TRACK);
// Check if a payload was sent
if (null != track) {
boolean newImage = false;
// Check if new album is played and remove image if it is.
if (mLastTrack == null || !track.getTrackAlbum().equals(mLastTrack.getTrackAlbum()) || !track.getTrackAlbumMBID().equals(mLastTrack.getTrackAlbumMBID())) {
mLastCover = null;
newImage = true;
}
// Save the information for later usage (when the asynchronous bitmap loader finishes)
mLastTrack = track;
if (newImage) {
CoverBitmapLoader coverLoader = new CoverBitmapLoader(context, new CoverReceiver(context, this));
coverLoader.getImage(track, false, -1, -1);
}
}
} else if (intent.getAction().equals(BackgroundService.ACTION_SERVER_DISCONNECTED)) {
mLastStatus = null;
mLastTrack = null;
} else if (intent.getAction().equals(ArtworkManager.ACTION_NEW_ARTWORK_READY)) {
// Check if the new artwork matches the currently playing track. If so reload artwork
if (mLastTrack != null && mLastTrack.getTrackAlbum().equals(intent.getStringExtra(ArtworkManager.INTENT_EXTRA_KEY_ALBUM_NAME))) {
// Got new artwork
mLastCover = null;
CoverBitmapLoader coverLoader = new CoverBitmapLoader(context, new CoverReceiver(context, this));
coverLoader.getImage(mLastTrack, false, -1, -1);
}
}
// Refresh the widget with the new information
updateWidget(context);
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus in project malp by gateship-one.
the class BackgroundService method checkMPDConnection.
/**
* Ensures an MPD server is connected before performing an action.
*/
private void checkMPDConnection() {
if (!MPDInterface.mInstance.isConnected() && !mConnecting) {
mNotificationManager.showNotification();
mLastTrack = new MPDTrack("");
mLastStatus = new MPDCurrentStatus();
connectMPDServer();
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus in project malp by gateship-one.
the class MPDStateMonitoringHandler method resynchronizeState.
private void resynchronizeState() {
// Stop the interpolation
stopInterpolation();
// If a resync timer is running kill it also. It will be restarted when idling again
stopResynchronization();
mLastTimeBase = System.nanoTime();
MPDCurrentStatus status = null;
try {
status = MPDInterface.mInstance.getCurrentServerStatus();
} catch (MPDException e) {
handleMPDError(e);
return;
}
if (status.getCurrentSongIndex() != mLastStatus.getCurrentSongIndex() || status.getPlaylistVersion() != mLastStatus.getPlaylistVersion()) {
// New track started playing. Get it and inform the listener.
try {
mLastFile = MPDInterface.mInstance.getCurrentSong();
} catch (MPDException e) {
handleMPDError(e);
}
distributeNewTrack(mLastFile);
}
mLastStatus = status;
distributeNewStatus(status);
startInterpolation();
}
Aggregations