android - Chromcast Remoteplayer seek to resume at seek 0 position when using nanohttpd -
chromcast remote player seek resume @ seek position 0 when using nanohttpd server. main issue getting when seek video player in device working fine on tv seek-bar set @ 0 position , music stat @ beginning.
when call mremotemediaplayer.seek() in onseekchanged() getting result success on tv seek-bar set @ 0 position , music stat @ beginning.
public class webserver extends nanohttpd { fileinputstream fileinputstream; public webserver(){ super(8080); } @override public response serve(string uri, method method, map<string, string> header,map<string, string> parameters, map<string, string> files) { string mediasend=" "; long size=0; fileinputstream fis = null; try { fis = new fileinputstream(path); //byte[] buffer = new byte[(int) fis.getchannel().size()]; size=fis.getchannel().size(); } catch (exception e) { e.printstacktrace(); } switch(mediatype){ case "photo": mediasend="image/jpeg"; break; case "audio": mediasend="audio/mp3"; break; case "video": mediasend="video/mp4"; break; } return new nanohttpd.response(com.castoffline.castactivity.nanohttpd.response.status.ok,mediasend,fis,size); } }
cast connection code
cast.castapi.launchapplication(mapiclient,getstring(r.string.app_id),false).setresultcallback(new resultcallback<cast.applicationconnectionresult>() { @override public void onresult(applicationconnectionresult result) { status status = result.getstatus(); if (status.issuccess()) { applicationmetadata applicationmetadata = result.getapplicationmetadata(); msessionid = result.getsessionid(); string applicationstatus = result.getapplicationstatus(); boolean waslaunched = result.getwaslaunched(); log.d(tag,"application name: "+ applicationmetadata.getname()+ ", status: "+ applicationstatus+ ", sessionid: "+ msessionid+ ", waslaunched: "+ waslaunched); mapplicationstarted = true; mremotemediaplayer = new remotemediaplayer(); /* * identify mediatype , send metadata details media info */ switch(mediatype) { case "audio" : mediametadata = new mediametadata(mediametadata.media_type_music_track); mediametadata.putstring(mediametadata.key_title, "my music track"+": "+audiotitle); mediametadata.putstring(mediametadata.key_artist,audioartist); mediametadata.addimage(new webimage(uri.parse("https://www.googledrive.com/host/0b61ekpen_94sz21mcnqtbvu2rhm/media.png"))); mediainfo = new mediainfo.builder(ipdevice).setcontenttype(mimetype).setstreamtype(mediainfo.stream_type_buffered).setmetadata(mediametadata).build(); break; case "video" : mediametadata = new mediametadata(mediametadata.media_type_movie); mediametadata.addimage(new webimage(uri.parse("https://www.googledrive.com/host/0b61ekpen_94sz21mcnqtbvu2rhm/film_reel.png"))); mediametadata.putstring(mediametadata.key_title, "my movie"+": "+videotitle); mediainfo = new mediainfo.builder(ipdevice).setcontenttype(mimetype).setstreamtype(mediainfo.stream_type_buffered).setmetadata(mediametadata).build(); break; case "photo" : mediametadata = new mediametadata(mediametadata.media_type_photo); mediametadata.putstring(mediametadata.key_title, "my photo"+": "); mediainfo = new mediainfo.builder(ipdevice).setcontenttype(mimetype).setstreamtype(mediainfo.stream_type_buffered).setmetadata(mediametadata).build(); break; default: } try { cast.castapi.setmessagereceivedcallbacks(mapiclient,mremotemediaplayer.getnamespace(), mremotemediaplayer); } catch (ioexception e) { log.d(tag, "exception while creating media channel", e); } try { mremotemediaplayer.load(mapiclient, mediainfo, false,0).setresultcallback(new resultcallback<remotemediaplayer.mediachannelresult>() { @override public void onresult(mediachannelresult result) { if (result.getstatus().issuccess()) { log.d(tag, "media loaded successfully"); } }}); /* * checks if video playing or if paused , according played/paused in receiver */ videoview.setplaypauselistener(new customvideoview.playpauselistener() { audiomanager amanager=(audiomanager)getsystemservice(context.audio_service); @override public void onplay() { playbackpaused=false; //videoview playing if(mselecteddevice!=null && mapiclient != null && mremotemediaplayer != null){ //volume set mute if media casting in chromecast amanager.setstreammute(audiomanager.stream_music, true); sendmediacontrol(playbackpaused,false); }else{ amanager.setstreamvolume(audiomanager.stream_music, 3,1); } } @override public void onpause(){ playbackpaused=true; //videoview paused if (mselecteddevice != null && mapiclient != null && mremotemediaplayer != null){ amanager.setstreammute(audiomanager.stream_music, false); sendmediacontrol(playbackpaused,false); }else{ amanager.setstreamvolume(audiomanager.stream_music, 3,1); } } /* seek function not working media playback while casting * (non-javadoc) * @see com.castoffline.castactivity.customvideoview.playpauselistener#onseekchanged(int) */ @override public void onseekchanged(int pos){ log.d(string.valueof(videoview.getcurrentposition()),"seekinsie"); // seek(videoview.getcurrentposition()); log.d("mimetype ",mimetype); log.d("seek1",""+pos); if (mselecteddevice != null && mapiclient != null && mremotemediaplayer != null){ videoview.pause(); final long position=videoview.getcurrentposition(); log.d("seek",""+position); mremotemediaplayer.seek(mapiclient,position,remotemediaplayer.resume_state_unchanged).setresultcallback(new resultcallback<remotemediaplayer.mediachannelresult>(){ @override public void onresult(mediachannelresult result) { if (result.getstatus().issuccess()) { log.d(string.valueof("state code "+result.getstatus().getstatuscode()),""+mremotemediaplayer.getapproximatestreamposition()); } } }); mremotemediaplayer.setonstatusupdatedlistener(new remotemediaplayer.onstatusupdatedlistener(){ @override public void onstatusupdated() { @suppresswarnings("unused") mediastatus mediastatus = mremotemediaplayer.getmediastatus(); log.d("seek state update",""+mediastatus); } }); } } }); } catch (illegalstateexception e) { log.d(tag, "problem occurred media during loading", e); } catch (exception e) { log.d(tag, "problem opening media during loading", e);} } else { log.e(tag,"application not launch"); teardown(); } } }); }
remote player control code.
private void sendmediacontrol(final boolean playbackpaused,final boolean change) { if (mapiclient != null && mremotemediaplayer != null){ mremotemediaplayer.requeststatus(mapiclient).setresultcallback( new resultcallback<remotemediaplayer.mediachannelresult>() { @override public void onresult(remotemediaplayer.mediachannelresult mediachannelresult) { if(playbackpaused ==true){ mremotemediaplayer.pause(mapiclient); }else{ mremotemediaplayer.play(mapiclient); } } }); } }
there can 2 things here:
- i don't know if limitation of nanohttpd or configuration issue seeing because nanaohttpd (at least way have configured it) doesn't support seek. when seek, receiver call http server (nanohttpd in case) , passes position , asks web server seek position , start streaming there. if web server doesn't support that, not able seek successfully. test, set apache server on laptop, testing, , point instead of embedded web server , see if works or not.
- there might mismatch between units of position; if, say, local player using seconds , reporting, say, 60 when minute content , if send cast receiver, interpreted 60 milliseconds practically same 0 seconds, check on too.
Comments
Post a Comment