Introduction to New Cast SDK (v3)

Introduction to New Cast SDK (v3)

6dd0483f1353a4a359e92633cfd65c64?s=128

Daichi Furiya (Wasabeef)

August 07, 2016
Tweet

Transcript

  1. New Google Cast SDK wasabeef shibuya.apk #9

  2. About me Daichi Furiya wasabeef @wasabeef_jp AbemaTV, Inc.

  3. Chromecast http://www.google.co.jp/intl/ja_jp/chromecast

  4. Sender

  5. Sender

  6. Sender

  7. Receiver

  8. Receiver

  9. Receiver

  10. Receiver

  11. Receiver

  12. Google Cast SDK v3

  13. Session state management Connect, disconnect, and reconnect logic UX implementation

    and UI Google Cast SDK v3
  14. Sender

  15. Gradle dependencies { compile "com.android.support:appcompat-v7:23.4.0" compile "com.android.support:mediarouter-v7:23.4.0" compile "com.google.android.gms:play-services-cast-framework:9.2.1" }

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

    Public CastOptions getCastOptions(Context context) { CastOptions castOptions = new CastOptions.Builder() .setReceiverApplicationId("415D36F5") .build(); return castOptions; } }
  17. Initialize the Cast Context <application> <meta-data android:name= "com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" android:value="com.foo.CastOptionsProvider" />

    </application>
  18. 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(); }
  19. 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; }
  20. Add a Cast Button

  21. IntroductoryOverlay

  22. IntroductoryOverlay new IntroductoryOverlay.Builder(this, button) .setTitleText("キャストを始めよう") .setOverlayColor(R.color.holo_blue_light) .setSingleTime() .build() .show();

  23. Add a Cast Button <android.support.v7.app.MediaRouteButton android:id="@+id/media_route_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:mediaRouteTypes="user" android:visibility="gone"

    /> @Override protected void onResume() { super.onResume(); CastButtonFactory.setUpMediaRouteButton(this, binding.mediaRouteButton); }
  24. 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); } }
  25. 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 } } }
  26. 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); } }
  27. 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);
  28. Recover from a temporary loss of WiFi Recover from device

    sleep Recover from backgrounding the app Recover if the app crashed Automatic Reconnection
  29. googlecast/ CastVideos-android

  30. Receiver

  31. Google Cast SDK Developer Console

  32. Custom Receiver Styled Media Receiver Remote Display Receiver Receiver

  33. Custom Receiver https://developers.google.com/cast/docs/custom_receiver

  34. googlecast/ CastReferencePlayer

  35. Conclusion

  36. Thank you. twitter.com/wasabeef_jp wasabeef.jp github.com/wasabeef