Search in sources :

Example 1 with MediaControl

use of com.connectsdk.service.capability.MediaControl in project butter-android by butterproject.

the class BeamPlayerNotificationService method handleIntent.

private void handleIntent(Intent intent) {
    if (intent == null || intent.getAction() == null) {
        return;
    }
    String action = intent.getAction();
    if (mediaControl == null) {
        Intent stopIntent = new Intent(getApplicationContext(), BeamPlayerNotificationService.class);
        stopService(stopIntent);
        return;
    }
    if (action.equalsIgnoreCase(ACTION_PLAY) || action.equalsIgnoreCase(ACTION_PAUSE)) {
        ResponseListener<Object> responseListener = new ResponseListener<Object>() {

            @Override
            public void onSuccess(Object object) {
                mediaControl.getPlayState(playStateListener);
            }

            @Override
            public void onError(ServiceCommandError error) {
                mediaControl.getPlayState(playStateListener);
            }
        };
        if (isPlaying) {
            isPlaying = false;
            mediaControl.pause(responseListener);
            buildNotification(generateAction(R.drawable.ic_av_play, "Play", ACTION_PLAY));
        } else {
            isPlaying = true;
            mediaControl.play(responseListener);
            buildNotification(generateAction(R.drawable.ic_av_pause, "Pause", ACTION_PAUSE));
        }
        mediaControl.getPlayState(playStateListener);
    } else if (action.equalsIgnoreCase(ACTION_FAST_FORWARD)) {
        mediaControl.getPosition(new MediaControl.PositionListener() {

            @Override
            public void onSuccess(Long object) {
                long seek = object + 10000;
                mediaControl.seek(seek, null);
            }

            @Override
            public void onError(ServiceCommandError error) {
            }
        });
    } else if (action.equalsIgnoreCase(ACTION_REWIND)) {
        mediaControl.getPosition(new MediaControl.PositionListener() {

            @Override
            public void onSuccess(Long object) {
                long seek = object - 10000;
                mediaControl.seek(seek, null);
            }

            @Override
            public void onError(ServiceCommandError error) {
            }
        });
    } else if (action.equalsIgnoreCase(ACTION_STOP)) {
        manager.stopVideo();
    }
}
Also used : MediaControl(com.connectsdk.service.capability.MediaControl) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 MediaControl (com.connectsdk.service.capability.MediaControl)1 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)1 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)1