video - Skipped Frames. Application may be doing too much work on it's main thread” error on android 4.3 nexus 7 -


import java.io.bufferedreader;  public class main extends activity implements surfaceholder.callback,         mediaplayer.oncompletionlistener, view.onclicklistener, oninitlistener {      string srcpath = "";     mediaplayer mp;     surfaceview msurfaceview;     private surfaceholder holderrrr;     boolean play = false;     string t_alarm1 = "alarm.xml", t_alarm2 = "alarm2.xml", text;      // texttospeach     private texttospeech mtext2speech;      @override     protected void oncreate(bundle savedinstancestate) {          strictmode.threadpolicy policy = new strictmode.threadpolicy.builder()                 .permitall().build();         strictmode.setthreadpolicy(policy);         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          addlisteneronbutton();         mtext2speech = new texttospeech(main.this, main.this);      }      // menü     @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         switch (item.getitemid()) {          case r.id.action_settings: {             intent myintent = new intent(this, menu.class);             main.this.startactivity(myintent);             return true;         }          }          return true;     }      // kilépésfigyelő      private static final long double_press_interval = 2000000000;// 2 másodperc     private long lastpresstime;      @override     public void onbackpressed() {         toast.maketext(main.this, getstring(r.string.kilepes_dupla),                 toast.length_short).show();         long presstime = system.nanotime();         if (presstime - lastpresstime <= double_press_interval) {             // double click event             system.exit(0);          }         lastpresstime = presstime;      }      public void oninit(int status) {          if (status == texttospeech.success) {             mtext2speech.setlanguage(locale.getdefault()); // alaértelmezett                                                             // nyelv tts-hez         }      }      private void addlisteneronbutton() {         final button button5 = (button) findviewbyid(r.id.button5);                       button5.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 // perform action on click                 if (play) {                     try{                         mp.stop();                         mp.release();                         mp = null;                     }catch(exception e){                      }                      button5.settext("start");                     play = false;                  } else {                     try {                         mp = new mediaplayer();                         msurfaceview = (surfaceview) findviewbyid(r.id.surface);                         holderrrr = msurfaceview.getholder();                         play = true;                         button5.settext("stop");                         surfacecreated(holderrrr);                     } catch (illegalargumentexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     } catch (securityexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     } catch (illegalstateexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }                 }              }         });      }// addlistener vége       public void surfacecreated(surfaceholder holder) {          mp.setdisplay(holder);          holder = msurfaceview.getholder();         holder.addcallback(this);         holder.settype(surfaceholder.surface_type_push_buffers);         try {             mp.setoncompletionlistener(new mediaplayer.oncompletionlistener() {                 @override                 public void oncompletion(mediaplayer mp) {                      mp.stop();                     mp.release();                     toast.maketext(main.this,                             "a videó lejátszás befejeződött!",                             toast.length_short).show();                     // button5.settext("start");                     //play = false;                   }             });             mp.setdatasource(srcpath);             mp.prepare();          } catch (illegalargumentexception e) {             // todo auto-generated catch block             e.printstacktrace();         } catch (securityexception e) {             // todo auto-generated catch block             e.printstacktrace();         } catch (illegalstateexception e) {             // todo auto-generated catch block             e.printstacktrace();         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }          // dimensions of video         // int videowidth = mp.getvideowidth();         // int videoheight = mp.getvideoheight();          // width of screen         // int screenwidth = getwindowmanager().getdefaultdisplay().getwidth();          // surfaceview layout parameters         android.view.viewgroup.layoutparams lp = msurfaceview.getlayoutparams();          // set width of surfaceview width of screen         // lp.width = screenwidth;         lp.width = 420;          // set height of surfaceview match aspect ratio of         // video         // sure cast these floats otherwise calculation         // 0         // lp.height = (int) (((float) videoheight / (float) videowidth) *         // (float) screenwidth);         lp.height = 390;          // commit layout parameters         msurfaceview.setlayoutparams(lp);          // start video         mp.start();     }               }            } 

it works fine on 4.1.2 android on galaxy s3 gives me error message in title. , doesn't show first 3 sec video... please give me advice or som solution because have no idea how rid of kind of error

in simple terms error means asking android system work on main thread of particular application. there general answers on error, 1 example being:

https://stackoverflow.com/a/21126690/334402

for specific example, may asking video related work, processor hungry, on main thread. worth looking @ 'prepare' method example , if using streamed source, consider using prepareasynch - see below android documentation:

public void prepareasync ()

added in api level 1 prepares player playback, asynchronously. after setting datasource , display surface, need either call prepare() or prepareasync(). streams, should call prepareasync(), returns immediately, rather blocking until enough data has been buffered.

one reason why may seeing problems on nexus 7 , not on galaxy 3 nexus has bigger screen , video source may offer different video encodings different sized devices - larger ones quite requiring more processing decode , render.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -