android - Streaming videos on VideoView -


i have simple videoview , i'm trying stream video url. here's code:

//everything in oncreate()  videoview = (videoview)findviewbyid(r.id.video);  string videoaddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4"; uri videouri = uri.parse(videoaddress);  videoview.setvideouri(videouri); videoview.start(); videocontroller = new mediacontroller(this); videocontroller.setanchorview(videoview); videoview.setmediacontroller(videocontroller); 

the problem:

it takes close 7-8 seconds start video. keeps buffering till then.

it isn't internet connectivity because played same video, in same internet , @ same time, in browser. (running browser parallel app). , took 1-2 seconds start video in browser.

i tried several other videos different sources, , i'm facing lag in of them.

similar questions has been asked several times on so, unanswered.

the problem was, doing in ui thread making take long time. in asynctask , things work out fine.

for beginners, this link describes how in asynctask.

define class extends asynctask:

public class backgroundasynctask extends asynctask<string, uri, void> {     integer track = 0;     progressdialog dialog;      protected void onpreexecute() {         dialog = new progressdialog(playvideo.this);         dialog.setmessage("loading, please wait...");         dialog.setcancelable(true);         dialog.show();     }      protected void onprogressupdate(final uri... uri) {          try {              media=new mediacontroller(playvideo.this);             video.setmediacontroller(media);             media.setprevnextlisteners(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     // next button clicked                  }             }, new view.onclicklistener() {                 @override                 public void onclick(view v) {                      finish();                 }             });             media.show(10000);              video.setvideouri(uri[0]);             video.requestfocus();             video.setonpreparedlistener(new onpreparedlistener() {                  public void onprepared(mediaplayer arg0) {                     video.start();                     dialog.dismiss();                 }             });           } catch (illegalargumentexception e) {             e.printstacktrace();         } catch (illegalstateexception e) {             e.printstacktrace();         } catch (securityexception e) {             // todo auto-generated catch block             e.printstacktrace();         }       }      @override     protected void doinbackground(string... params) {         try {             uri uri = uri.parse(params[0]);              publishprogress(uri);         } catch (exception e) {             e.printstacktrace();          }          return null;     }  } 

then, in oncreate() method, call execute() method of backgroundasynchtask:

video = (videoview) findviewbyid(r.id.video); new backgroundasynctask().execute("link-to-the-video"); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -