Java Code Examples for android.media.RemoteControlClient#PLAYSTATE_PLAYING

The following examples show how to use android.media.RemoteControlClient#PLAYSTATE_PLAYING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicTile.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private void playbackStateUpdate(int state) {
    boolean active;
    switch (state) {
        case RemoteControlClient.PLAYSTATE_PLAYING:
            active = true;
            break;
        case RemoteControlClient.PLAYSTATE_ERROR:
        case RemoteControlClient.PLAYSTATE_PAUSED:
        default:
            active = false;
            break;
    }
    if (active != mActive) {
        mActive = active;
        refreshState();
        if (DEBUG) log(getKey() + ": playbackStateUpdate("+state+")");
    }
}
 
Example 2
Source File: MediaProviderDelegate.java    From Noyze with Apache License 2.0 6 votes vote down vote up
static int getStateFromPlayState(PlayState playState) {
    switch (playState) {
        case BUFFERING:
            return RemoteControlClient.PLAYSTATE_BUFFERING;
        case ERROR:
            return RemoteControlClient.PLAYSTATE_ERROR;
        case FAST_FORWARDING:
            return RemoteControlClient.PLAYSTATE_FAST_FORWARDING;
        case PAUSED:
            return RemoteControlClient.PLAYSTATE_PAUSED;
        case PLAYING:
            return RemoteControlClient.PLAYSTATE_PLAYING;
        case REWINDING:
            return RemoteControlClient.PLAYSTATE_REWINDING;
        case SKIPPING_BACKWARDS:
            return RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS;
        case SKIPPING_FORWARDS:
            return RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS;
        case STOPPED:
            return RemoteControlClient.PLAYSTATE_STOPPED;
        default:
            return RemoteControlClient.PLAYSTATE_ERROR;
    }
}
 
Example 3
Source File: PlaybackInfo.java    From Noyze with Apache License 2.0 6 votes vote down vote up
public boolean wasPlayingRecently() {
    switch (mState) {
        case RemoteControlClient.PLAYSTATE_PLAYING:
        case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
        case RemoteControlClient.PLAYSTATE_REWINDING:
        case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
        case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
        case RemoteControlClient.PLAYSTATE_BUFFERING:
            // actively playing or about to play
            return true;
        case RemoteControlClient.PLAYSTATE_STOPPED:
        case RemoteControlClient.PLAYSTATE_PAUSED:
        case RemoteControlClient.PLAYSTATE_ERROR:
            return ((SystemClock.elapsedRealtime() - mStateChangeTimeMs) < DISPLAY_TIMEOUT_MS);
        default:
            LOGE("PlaybackInfo", "Unknown playback state " + mState + " in wasPlayingRecently()");
            return false;
    }
}
 
Example 4
Source File: PlaybackInfo.java    From Noyze with Apache License 2.0 6 votes vote down vote up
public boolean wasPlayingRecently() {
    switch (mState) {
        case RemoteControlClient.PLAYSTATE_PLAYING:
        case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
        case RemoteControlClient.PLAYSTATE_REWINDING:
        case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
        case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
        case RemoteControlClient.PLAYSTATE_BUFFERING:
            // actively playing or about to play
            return true;
        case RemoteControlClient.PLAYSTATE_STOPPED:
        case RemoteControlClient.PLAYSTATE_PAUSED:
        case RemoteControlClient.PLAYSTATE_ERROR:
            return ((SystemClock.elapsedRealtime() - mStateChangeTimeMs) < DISPLAY_TIMEOUT_MS);
        default:
            LOGE("PlaybackInfo", "Unknown playback state " + mState + " in wasPlayingRecently()");
            return false;
    }
}
 
Example 5
Source File: MediaProviderDelegate.java    From Noyze with Apache License 2.0 6 votes vote down vote up
static int getStateFromPlayState(PlayState playState) {
    switch (playState) {
        case BUFFERING:
            return RemoteControlClient.PLAYSTATE_BUFFERING;
        case ERROR:
            return RemoteControlClient.PLAYSTATE_ERROR;
        case FAST_FORWARDING:
            return RemoteControlClient.PLAYSTATE_FAST_FORWARDING;
        case PAUSED:
            return RemoteControlClient.PLAYSTATE_PAUSED;
        case PLAYING:
            return RemoteControlClient.PLAYSTATE_PLAYING;
        case REWINDING:
            return RemoteControlClient.PLAYSTATE_REWINDING;
        case SKIPPING_BACKWARDS:
            return RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS;
        case SKIPPING_FORWARDS:
            return RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS;
        case STOPPED:
            return RemoteControlClient.PLAYSTATE_STOPPED;
        default:
            return RemoteControlClient.PLAYSTATE_ERROR;
    }
}
 
Example 6
Source File: Constants.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public static boolean isRemoteControlPlaying(final int state) {
    switch (state) {
        case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
        case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
        case RemoteControlClient.PLAYSTATE_BUFFERING:
        case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
        case RemoteControlClient.PLAYSTATE_PLAYING:
        case RemoteControlClient.PLAYSTATE_REWINDING:
            return true;
    }

    return false;
}
 
Example 7
Source File: TransportMediatorJellybeanMR2.java    From guideshow with MIT License 5 votes vote down vote up
public void startPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PLAYING;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }
    if (mFocused) {
        takeAudioFocus();
    }
}
 
Example 8
Source File: TransportMediatorJellybeanMR2.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
public void pausePlaying() {
    if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PAUSED;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
    }
    dropAudioFocus();
}
 
Example 9
Source File: TransportMediatorJellybeanMR2.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
public void startPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PLAYING;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }
    if (mFocused) {
        takeAudioFocus();
    }
}
 
Example 10
Source File: TransportMediatorJellybeanMR2.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
void gainFocus() {
    if (!mFocused) {
        mFocused = true;
        mAudioManager.registerMediaButtonEventReceiver(mPendingIntent);
        mAudioManager.registerRemoteControlClient(mRemoteControl);
        if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
            takeAudioFocus();
        }
    }
}
 
Example 11
Source File: Constants.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public static boolean isRemoteControlPlaying(final int state) {
    switch (state) {
        case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
        case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
        case RemoteControlClient.PLAYSTATE_BUFFERING:
        case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
        case RemoteControlClient.PLAYSTATE_PLAYING:
        case RemoteControlClient.PLAYSTATE_REWINDING:
            return true;
    }

    return false;
}
 
Example 12
Source File: TransportMediatorJellybeanMR2.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public void pausePlaying() {
    if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PAUSED;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
    }
    dropAudioFocus();
}
 
Example 13
Source File: TransportMediatorJellybeanMR2.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
void gainFocus() {
    if (!mFocused) {
        mFocused = true;
        mAudioManager.registerMediaButtonEventReceiver(mPendingIntent);
        mAudioManager.registerRemoteControlClient(mRemoteControl);
        if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
            takeAudioFocus();
        }
    }
}
 
Example 14
Source File: TransportMediatorJellybeanMR2.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void pausePlaying() {
    if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PAUSED;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
    }
    dropAudioFocus();
}
 
Example 15
Source File: TransportMediatorJellybeanMR2.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void startPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PLAYING;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }
    if (mFocused) {
        takeAudioFocus();
    }
}
 
Example 16
Source File: TransportMediatorJellybeanMR2.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
void gainFocus() {
    if (!mFocused) {
        mFocused = true;
        mAudioManager.registerMediaButtonEventReceiver(mPendingIntent);
        mAudioManager.registerRemoteControlClient(mRemoteControl);
        if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
            takeAudioFocus();
        }
    }
}
 
Example 17
Source File: RemoteControlClientJB.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setPlaybackState(final int state, int index, int queueSize) {
	if(mRemoteControl == null) {
		return;
	}

	long position = -1;
	if(state == RemoteControlClient.PLAYSTATE_PLAYING || state == RemoteControlClient.PLAYSTATE_PAUSED) {
		position = downloadService.getPlayerPosition();
	}
	mRemoteControl.setPlaybackState(state, position, 1.0f);
}
 
Example 18
Source File: NotificationListenerService.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onClientPlaybackStateUpdate(int state) {
    this.isRemoteControllerPlaying = state == RemoteControlClient.PLAYSTATE_PLAYING;
}
 
Example 19
Source File: NotificationListenerService.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onClientPlaybackStateUpdate(int state, long stateChangeTimeMs, long currentPosMs, float speed) {
    this.isRemoteControllerPlaying = state == RemoteControlClient.PLAYSTATE_PLAYING;
    mHasBug = false;
    if (currentPosMs > 3600000)
        currentPosMs = -1L;
    SharedPreferences current = getSharedPreferences("current_music", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = current.edit();
    editor.putLong("position", currentPosMs);

    if (isRemoteControllerPlaying) {
        long currentTime = System.currentTimeMillis();
        editor.putLong("startTime", currentTime);
    } else {
        NotificationManager notificationManager =
                ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
        notificationManager.cancel(NOTIFICATION_ID);
        notificationManager.cancel(8);
    }
    editor.putBoolean("playing", isRemoteControllerPlaying);
    editor.apply();

    if (App.isMainActivityVisible() && isRemoteControllerPlaying) {
        Intent internalIntent = new Intent(LyricsViewFragment.UPDATE_LYRICS_ACTION);
        internalIntent
                .putExtra("artist", current.getString("artist", ""))
                .putExtra("track", current.getString("track", ""));
        LyricsViewFragment.sendIntent(NotificationListenerService.this, internalIntent);
    }
    Log.d("geecko", "PlaybackStateUpdate - position stored: " + currentPosMs);

    long position = getRemotePlayerPosition();

    if (durationObject instanceof Double) {
        if (artist != null && !artist.isEmpty())
            mediaControllerCallback.broadcast(this, artist, track, isRemoteControllerPlaying, (Double) durationObject, position, null);
    } else if (durationObject instanceof Integer) {
        if (artist != null && !artist.isEmpty())
            mediaControllerCallback.broadcast(this, artist, track, isRemoteControllerPlaying, (Integer) durationObject, position, null);
    } else if (durationObject instanceof Long)
        if (artist != null && !artist.isEmpty())
            mediaControllerCallback.broadcast(this, artist, track, isRemoteControllerPlaying, (Long) durationObject, position, null);
}
 
Example 20
Source File: RemoteControlClientLP.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setPlaybackState(int state, int index, int queueSize) {
	PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();

	int newState = PlaybackStateCompat.STATE_NONE;
	switch(state) {
		case RemoteControlClient.PLAYSTATE_PLAYING:
			newState = PlaybackStateCompat.STATE_PLAYING;
			break;
		case RemoteControlClient.PLAYSTATE_STOPPED:
			newState = PlaybackStateCompat.STATE_STOPPED;
			break;
		case RemoteControlClient.PLAYSTATE_PAUSED:
			newState = PlaybackStateCompat.STATE_PAUSED;
			break;
		case RemoteControlClient.PLAYSTATE_BUFFERING:
			newState = PlaybackStateCompat.STATE_BUFFERING;
			break;
	}

	long position = -1;
	if(state == RemoteControlClient.PLAYSTATE_PLAYING || state == RemoteControlClient.PLAYSTATE_PAUSED) {
		position = downloadService.getPlayerPosition();
	}
	builder.setState(newState, position, 1.0f);
	DownloadFile downloadFile = downloadService.getCurrentPlaying();
	Entry entry = null;
	boolean isSong = true;
	if(downloadFile != null) {
		entry = downloadFile.getSong();
		isSong = entry.isSong();
	}

	builder.setActions(getPlaybackActions(isSong, index, queueSize));

	if(entry != null) {
		addCustomActions(entry, builder);
		builder.setActiveQueueItemId(entry.getId().hashCode());
	}

	PlaybackStateCompat playbackState = builder.build();
	mediaSession.setPlaybackState(playbackState);
	previousState = state;
}