Search in sources :

Example 6 with MPDCurrentStatus

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);
    }
}
Also used : MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus)

Example 7 with MPDCurrentStatus

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));
    }
}
Also used : MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus)

Example 8 with MPDCurrentStatus

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);
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus) CoverBitmapLoader(org.gateshipone.malp.application.utils.CoverBitmapLoader)

Example 9 with MPDCurrentStatus

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();
    }
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus)

Example 10 with MPDCurrentStatus

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();
}
Also used : MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus) MPDException(org.gateshipone.malp.mpdservice.mpdprotocol.MPDException)

Aggregations

MPDCurrentStatus (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus)11 MPDException (org.gateshipone.malp.mpdservice.mpdprotocol.MPDException)3 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)3 IntentFilter (android.content.IntentFilter)1 MenuInflater (android.view.MenuInflater)1 List (java.util.List)1 CoverBitmapLoader (org.gateshipone.malp.application.utils.CoverBitmapLoader)1 CurrentPlaylistView (org.gateshipone.malp.application.views.CurrentPlaylistView)1 MPDResponseAlbumList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList)1 MPDResponseArtistList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList)1 MPDResponseFileList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList)1 MPDResponseHandler (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseHandler)1 MPDResponseOutputList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseOutputList)1 MPDCapabilities (org.gateshipone.malp.mpdservice.mpdprotocol.MPDCapabilities)1 MPDCommands (org.gateshipone.malp.mpdservice.mpdprotocol.MPDCommands)1 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)1 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)1 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)1 MPDOutput (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDOutput)1 MPDStatistics (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDStatistics)1