Search in sources :

Example 1 with VideoCastManager

use of com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager in project Shuttle by timusus.

the class VideoIntentReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null) {
        return;
    }
    VideoCastManager castManager = VideoCastManager.getInstance();
    switch(action) {
        case VideoCastNotificationService.ACTION_TOGGLE_PLAYBACK:
            try {
                castManager.togglePlayback();
            } catch (CastException | TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "onReceive() Failed to toggle playback");
            }
            break;
        case VideoCastNotificationService.ACTION_PLAY_NEXT:
            try {
                castManager.queueNext(null);
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "onReceive() Failed to skip to the next in queue");
            }
            break;
        case VideoCastNotificationService.ACTION_PLAY_PREV:
            try {
                castManager.queuePrev(null);
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "onReceive() Failed to skip to the previous in queue");
            }
            break;
        case VideoCastNotificationService.ACTION_FORWARD:
            int forwardAmount = intent.getIntExtra(VideoCastNotificationService.EXTRA_FORWARD_STEP_MS, 0);
            try {
                castManager.forward(forwardAmount);
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "onReceive() Failed to forward the media");
            }
            break;
        case VideoCastNotificationService.ACTION_REWIND:
            int rewindAmount = intent.getIntExtra(VideoCastNotificationService.EXTRA_FORWARD_STEP_MS, 0);
            try {
                castManager.forward(rewindAmount);
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "onReceive() Failed to rewind the media");
            }
            break;
        case VideoCastNotificationService.ACTION_STOP:
            LOGD(TAG, "Calling stopApplication from intent");
            castManager.disconnectDevice(true, true, true);
            // persistent notification if other things go wrong
            if (castManager.getNotificationServiceClass() != null) {
                context.stopService(new Intent(context, castManager.getNotificationServiceClass()));
            }
            break;
        case Intent.ACTION_MEDIA_BUTTON:
            // Lollipop
            if (!intent.hasExtra(Intent.EXTRA_KEY_EVENT)) {
                return;
            }
            KeyEvent keyEvent = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
            if (keyEvent == null || keyEvent.getAction() != KeyEvent.ACTION_DOWN) {
                return;
            }
            if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
                try {
                    castManager.togglePlayback();
                } catch (CastException | TransientNetworkDisconnectionException | NoConnectionException e) {
                    LOGE(TAG, "onReceive() Failed to toggle playback ");
                }
            }
            break;
    }
}
Also used : KeyEvent(android.view.KeyEvent) VideoCastManager(com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) Intent(android.content.Intent) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Example 2 with VideoCastManager

use of com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager in project Shuttle by timusus.

the class CaptionsPreferenceActivity method onCreate.

// For getPreferenceScreen() and addPreferenceFromResource(); due to the API levels supported
// in this library, we cannot move to fragment-based preferences.
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    VideoCastManager castManager = VideoCastManager.getInstance();
    if (!castManager.isFeatureEnabled(CastConfiguration.FEATURE_CAPTIONS_PREFERENCE)) {
        LOGE(TAG, "Did you forget to enable FEATURE_CAPTIONS_PREFERENCE when you initialized" + " the VideoCastManage?");
        finish();
        return;
    }
    if (Utils.IS_KITKAT_OR_ABOVE) {
        startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
        finish();
        return;
    }
    addPreferencesFromResource(R.xml.caption_preference);
    castManager.getTracksPreferenceManager().setUpPreferences(getPreferenceScreen());
}
Also used : VideoCastManager(com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)2 VideoCastManager (com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager)2 KeyEvent (android.view.KeyEvent)1 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)1 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)1 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)1