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;
}
}
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());
}
Aggregations