android - Creating a custom receiver with the Google Cast - Media Player Library -



android - Creating a custom receiver with the Google Cast - Media Player Library -

i implement media player functionality custom receiver. on google developer website, found description implement sender , styled media receiver application.

i have done sample, , works fine. can cast mp3 file hosted on google drive chromecast device.

now, have implemented custom receiver (see attachment) should able play url refered m3u8 file. this, using media player library suggested google.

<body> <div> <p id='text'> </p> <video id='vid'> </video> </div> <script type="text/javascript" src="https://www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script> <script type="text/javascript" src="https://www.gstatic.com/cast/sdk/libs/mediaplayer/1.0.0/media_player.js"></script> <script type="text/javascript"> // if set ?debug=true in url, such different app id in // developer console, include debugging information. if (window.location.href.indexof('debug=true') != -1) { cast.receiver.logger.setlevelvalue(cast.receiver.loggerlevel.debug); cast.player.api.setloggerlevel(cast.player.api.loggerlevel.debug); } console.log("mediaelement set"); var mediaelement = document.getelementbyid('vid'); // create media manager. handle media messages default. window.mediamanager = new cast.receiver.mediamanager(mediaelement); // remember default value receiver onload, sample can play // non-adaptive media well. window.defaultonload = mediamanager.onload; mediamanager.onload = function (event) { // media player library requires phone call player unload between // different invocations. if (window.player !== null) { player.unload(); // must unload before starting again. window.player = null; } // trivial parser no means best practice, shows how access // event data, , uses string search of suffix, rather looking // @ mime type better. in practice, know // content serving while writing player. if (event.data['media'] && event.data['media']['contentid']) { console.log('starting media application'); var t = document.getelementbyid('text'); t.innerhtml = event.data['media']; console.log("eventdata: "+event.data); console.log("eventdata-media: "+event.data['media']); console.log("eventdata-contendid: "+event.data['media']['contentid']); var url = event.data['media']['contentid']; console.log("url: "+url); // create host - much of interaction library uses host , // methods provide it. window.host = new cast.player.api.host( {'mediaelement':mediaelement, 'url':url}); var ext = url.substring(url.lastindexof('.'), url.length); var initstart = event.data['media']['currenttime'] || 0; var autoplay = event.data['autoplay'] || true; var protocol = null; mediaelement.autoplay = autoplay; // create sure autoplay get's set protocol = cast.player.api.createhlsstreamingprotocol(host); host.onerror = function(errorcode) { console.log("fatal error - "+errorcode); if (window.player) { window.player.unload(); window.player = null; } }; // if need cookies, set withcredentials = true set header // info need. if don't need them, there can unexpected // effects setting value. // host.updatesegmentrequestinfo = function(requestinfo) { // requestinfo.withcredentials = true; // }; console.log("we have protocol "+ext); if (protocol !== null) { console.log("starting media player library"); window.player = new cast.player.api.player(host); window.player.load(protocol, initstart); } else { window.defaultonload(event); // default process } } } window.player = null; console.log('application ready, starting system'); window.castreceivermanager = cast.receiver.castreceivermanager.getinstance(); castreceivermanager.start(); </script> </body>

i've figured out, it's possible cast .m3u8, .ism , .mpd files media player library. created m3u8 file follows, host google drive, , tried cast custom receiver.

#extm3u #ext-x-stream-inf:program-id=1,bandwidth=173952 https://www.googledrive.com/host/0b1x31llraxtmrndtnkhswvdglve

but doesn't works. used goolge cast developer console debug custom receiver. exceuting

window.player.load(protocol, initstart);

command, fatal error on console.

i think problem on custom receiver code because sender application google documentation works fine styled media receiver.

is there know problem or see issue on custom receiver code? has thought how debug styled media player? much easier if see messages exchanged styled media player if activate debugging can´t see exchanged messages.

if turn on debugging, can see message exchanges (see here, under debugging section). there total fledged receiver sample project on our github repo well.

android casting chromecast google-cast custom-receiver

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -