Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to New Cast SDK (v3)

Introduction to New Cast SDK (v3)

Daichi Furiya (Wasabeef)

August 07, 2016
Tweet

More Decks by Daichi Furiya (Wasabeef)

Other Decks in Programming

Transcript

  1. Initialize the Cast Context class CastOptionsProvider implements OptionsProvider { @Override

    Public CastOptions getCastOptions(Context context) { CastOptions castOptions = new CastOptions.Builder() .setReceiverApplicationId("415D36F5") .build(); return castOptions; } }
  2. Initialize the Cast Context @Override public CastOptions getCastOptions(Context context) {

    NotificationOptions notificationOptions = new NotificationOptions.Builder() .setActions(Arrays.asList(MediaIntentReceiver.ACTION_SKIP_NEXT, MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK, MediaIntentReceiver.ACTION_STOP_CASTING), new int[]{1, 2}) .setTargetActivityClassName(ExpandedControlsActivity.class.getName()) .build(); CastMediaOptions mediaOptions = new CastMediaOptions.Builder() .setNotificationOptions(notificationOptions) .build(); return new CastOptions.Builder() .setReceiverApplicationId("415D36F5") .setCastMediaOptions(mediaOptions) .build(); }
  3. Initialize the Cast Context @Override public CastOptions getCastOptions(Context context) {

    NotificationOptions notificationOptions = new NotificationOptions.Builder() .setTargetActivityClassName(MainActivity.class.getName()).build(); CastMediaOptions castMediaOptions = new CastMediaOptions.Builder() .setNotificationOptions(notificationOptions).build(); CastOptions castOptions = new CastOptions.Builder().setReceiverApplicationId("415D36F5") .setEnableReconnectionService(true) .setResumeSavedSession(true) .setCastMediaOptions(castMediaOptions) .setSupportedNamespaces(Collections.singletonList("urn:x-cast:jp.wasabeef")) .build(); return castOptions; }
  4. How session management works public class MainActivity extends Activity {

    private CastSession castSession; private SessionManager sessionManager; private SessionManagerListener listener = new SessionManagerListener<CastSession>(){ @Override public void onSessionStarted(Session session, String sessionId) { // Connected } @Override public void onSessionEnded(Session session, int error) { // Disconnected } } @Override protected void onCreate() { super.onCreate(); CastContext cc = CastContext.getSharedInstance(this); sessionManager = cc.getSessionManager(); sessionManager.addSessionManagerListener(listener); } }
  5. How session management works public class MainActivity extends Activity {

    // … private CastSession castSession; private SessionManagerListener listener = new SessionManagerListener<CastSession>(){ @Override public void onSessionStarted(Session session, String sessionId) { // Connected } @Override public void onSessionEnded(Session session, int error) { // Disconnected } } }
  6. How session management works public class MainActivity extends Activity {

    private CastSession castSession; private SessionManager sessionManager; private SessionManagerListener listener; // … @Override protected void onCreate() { super.onCreate(); CastContext cc = CastContext.getSharedInstance(this); sessionManager = cc.getSessionManager(); sessionManager.addSessionManagerListener(listener); } }
  7. Load Media MediaMetadata meta = new MediaMetadata(MediaMetadata.MEDIA_TYPE_TV_SHOW); meta.putString(MediaMetadata.KEY_TITLE, “わさビーフの奇妙な冒険 #1”);

    meta.putString(MediaMetadata.KEY_SUBTITLE, "堅あげポテトは砕けない "); meta.addImage(new WebImage(Uri.parse(“https://wasabeef.jp/cover.webp")); MediaInfo mediaInfo = new MediaInfo.Builder(“https://wasabeef.jp/jojo-anim.m3u8") .setStreamType(streamType) .setContentType("application/x-mpegurl") .setMetadata(meta) .setCustomData(/** カスタムデータ:JSONObject **/) .build(); RemoteMediaClient client = castSession.getRemoteMediaClient(); client.load(mediaInfo, true, 0);
  8. Recover from a temporary loss of WiFi Recover from device

    sleep Recover from backgrounding the app Recover if the app crashed Automatic Reconnection