view - Android AsyncTask accessing and updating VideoView -
i need monitor buffer percentage of videoview continuously while video playing on foreground. created asynctask class , passed videoview on class. however, when try access buffer percentage return 0. initialized , started video playback on oncreate method of main activity. code:
public class mainactivity extends activity { static mediacontroller mc; static videoview vw; /** called when activity first created. */ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.activity_main); mc = new mediacontroller(this); vw = (videoview) findviewbyid(r.id.videoview); vw.setvideopath("http://173.45.164.105:1935/live/mystream/playlist.m3u8"); vw.requestfocus(); vw.start(); // execute async task stream error conncheck cc = new conncheck(); cc.execute(); log.i("reached main", "started playing"); }
}
class conncheck extends asynctask<void, void, void>{ @override protected void doinbackground(void... params) { while (mainactivity.vw.isplaying() == true) { log.i("hey", "doing stuff"); } return null; }
you starting video in oncreate()
method, @ instant has not started playing , execute asynctask after starting video. when doinbackground()
exceuted, mainactivity.vw.isplaying()
returns false , hence vm never enters loop have created. hope understand difference between started , playing.
, solution of problem implement method
public abstract void onbufferingupdate (mediaplayer mp, int percent)
Comments
Post a Comment