android - Cast Video to TV using MediaRouteButton -


i planning use this small library called "casty" (built upon google cast v3) implement video casting functionality in app.

i want achieve casting youtube video(s) like this one

here code, i've copied (this should play video on android tv via chromecast via web based video url):

public class mainactivity extends appcompatactivity {     private button playbutton;     private casty casty;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          casty = casty.create(this)                 .withminicontroller();         setupplaybutton();         setupmediaroutebutton();     }      private void setupplaybutton() {         playbutton = (button) findviewbyid(r.id.button_play);         playbutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 casty.getplayer().loadmediaandplay(createsamplemediadata());             }         });         casty.setonconnectchangelistener(new casty.onconnectchangelistener() {             @override             public void onconnected() {                 playbutton.setenabled(true);             }              @override             public void ondisconnected() {                 playbutton.setenabled(false);             }         });     }      private void setupmediaroutebutton() {         mediaroutebutton mediaroutebutton = (mediaroutebutton) findviewbyid(r.id.media_route_button);         casty.setupmediaroutebutton(mediaroutebutton);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         super.oncreateoptionsmenu(menu);         casty.addmediaroutemenuitem(menu);         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      private static mediadata createsamplemediadata() {         return new mediadata.builder("http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_30fps_normal.mp4")                 .setstreamtype(mediadata.stream_type_buffered)                 .setcontenttype("videos/mp4")                 .setmediatype(mediadata.media_type_movie)                 .settitle("sample title")                 .setsubtitle("sample subtitle")                 .addphotourl("https://peach.blender.org/wp-content/uploads/bbb-splash.png?x11217")                 .build();     } } 

note: i've not checked yet, because don't have things required test casting functionality... chromecast , tv

my requirement

instead of web based video url, if cast youtube video using same lib, hope code should look or not:

return new mediadata.builder("https://www.youtube.com/watch?v=rkjupqcxnsm") 

i have 2 questions in mind:

1. shall need keep play , pause buttons (in case of youtube video) ?

what think: think, not need use play , pause buttons separately control media playback (because youtube handle itself) - right or wrong ?

  1. if right, , when need use createsamplemediadata() method

so think how our mainactivity.java should in case of casting youtube video ?

the bad thing is, don't have tv, otherwise, can give many tries done. 

this hard without testing device, since android tv emulator cannot use test cast functionality. can check out document get started, familiar cast api functionalities. may want check related post talks playing web videos cast api. there document list of video formats supported.

hope helps.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -