failed to load video stream in android -
hey guys developing tv station live streaming android application have url of streaming engine http://197.243.19.131:1935/rtv/rtv/playlist.m3u8
anyone can me find out how play video url in android please have tried write codes here:
string stream_url="http://197.243.19.131:1935/rtv/rtv/playlist.m3u8"; view rootview = inflater.inflate(r.layout.fragment_two, container, false); videoview=(videoview)rootview.findviewbyid(r.id.videostream); uri uri= uri.parse(stream_url); videoview.setvideouri(uri); videoview.start();
you need dive little more media , streaming, though have declared view render video haven't handled media yet. need use media player api provided android stream m3u8.it pretty simple play live content follow code.
public class playeractivity extends appcompatactivity implements surfaceholder.callback, mediaplayer.onpreparedlistener { private string downloadurl; private int playminute; private surfaceview msurfaceview; private mediaplayer mmediaplayer; private surfaceholder msurfaceholder; progressbar p_bar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.player); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); view decorview = getwindow().getdecorview(); // hide both navigation bar , status bar. // system_ui_flag_fullscreen available on android 4.1 , higher, // general rule, should design app hide status bar whenever // hide navigation bar. int uioptions = view.system_ui_flag_hide_navigation | view.system_ui_flag_fullscreen; decorview.setsystemuivisibility(uioptions); // thumburl = getintent().getstringextra("thumburl"); // p_bar=(progressbar)findviewbyid(r.id.p_bar); // entryid = getintent().getstringextra("entryid"); // playminute = getintent().getintextra("playminute",0); //fragmenttype = getintent().getstringextra("fragmenttype"); // downloadurl = getintent().getstringextra("downloadurl"); downloadurl = "http://197.243.19.131:1935/rtv/rtv/playlist.m3u8"; // description = getintent().getstringextra("description"); log.e("kanish","download url inside player:"+downloadurl); msurfaceview = (surfaceview) findviewbyid(r.id.surface_view); msurfaceholder = msurfaceview.getholder(); msurfaceholder.addcallback(playeractivity.this); } @override public void surfacecreated(surfaceholder holder) { p_bar.setvisibility(view.visible); mmediaplayer = new mediaplayer(); mmediaplayer.setdisplay(msurfaceholder); try { mmediaplayer.setdatasource(downloadurl); mmediaplayer.prepare(); mmediaplayer.setonpreparedlistener(playeractivity.this); //mmediaplayer.setaudiostreamtype(audiomanager.stream_music); } catch (ioexception e) { e.printstacktrace(); } } @override public void surfacechanged(surfaceholder holder, int format, int width, int height) { } @override public void surfacedestroyed(surfaceholder holder) { } @override public void onbackpressed() { super.onbackpressed(); } @override public void onprepared(mediaplayer mp) { p_bar.setvisibility(view.gone); mmediaplayer.start(); } @override protected void onpause() { super.onpause(); releasemediaplayer(); } @override protected void ondestroy() { super.ondestroy(); releasemediaplayer(); } private void releasemediaplayer() { if (mmediaplayer != null) { mmediaplayer.release(); mmediaplayer = null; } } }
let me know if helps.
Comments
Post a Comment