java - Create a videoplayer with the LibVLC for android -


i trying creat video player android app last libvlc.

the problem don't know how lib works , can't find sample me (as here https://bitbucket.org/edwardcw/libvlc-android-sample)

so try on own create video player :

public class videoplayeractivity extends appcompatactivity implements ivideoplayer, gesturedetector.ondoubletaplistener, idelaycontroller {  private static libvlc libvlc() {     return vlcinstance.get(); }  private static mediaplayer mediaplayer() {     return vlcinstance.getmainmediaplayer(); }  @override @targetapi(build.version_codes.jelly_bean_mr1) protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      toast.maketext(getapplicationcontext(), "ca start videoplayeractivity !!", toast.length_short).show();     if (!vlcinstance.testcompatiblecpu(this)) {        // exit(result_canceled);         return;     }     extras = getintent().getextras();     muri = extras.getparcelable(play_extra_item_location);     toast.maketext(getapplicationcontext(), "oui ça start le videoplayer", toast.length_short).show();     setcontentview(r.layout.player_test); }  @override public  void onresume() {     super.onresume();      msurfaceview = (surfaceview) findviewbyid(r.id.player_surface_test);     setsurfacelayout(100, 100, 100, 100, 100, 100);     msurfaceholder = msurfaceview.getholder();     msurfaceframe = (framelayout) findviewbyid(r.id.player_surface_frame_test);     msurfaceholder.addcallback(msurfacecallback); }  private static class configuresurfaceholder {     private final surface surface;     private boolean configured;      private configuresurfaceholder(surface surface) {         this.surface = surface;     } }  @override public void setsurfacelayout(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den) {      /*if (width * height == 0)         return;*/      // store video size     mvideoheight = height;     mvideowidth = width;     mvideovisibleheight = visible_height;     mvideovisiblewidth  = visible_width;     msarnum = sar_num;     msarden = sar_den;    toast.maketext(this, "mvideoheight = " + mvideoheight, toast.length_short).show(); }  @override public int configuresurface(surface surface, final int width, final int height, final int hal) {     if (androidutil.isicsorlater() || surface == null)         return -1;     if (width * height == 0)         return 0;     log.i(tag, "configuresurface: " + width +"x"+height);      final configuresurfaceholder holder = new configuresurfaceholder(surface);      final handler handler = new handler(looper.getmainlooper());     handler.post(new runnable() {         @override         public void run() {             if (msurface == holder.surface && msurfaceholder != null) {                 if (hal != 0)                     msurfaceholder.setformat(hal);                 msurfaceholder.setfixedsize(width, height);             }             synchronized (holder) {                 holder.configured = true;                 holder.notifyall();             }         }     });     try {         synchronized (holder) {             while (!holder.configured)                 holder.wait();         }     } catch (interruptedexception e) {         return 0;     }     return 1; }  @override public void eventhardwareaccelerationerror() { }  private void startvideo() {     // libvlc lib = new libvlc();     mmediaplayer = vlcinstance.getmainmediaplayer();     media media = new media(vlcinstance.get(), muri.getpath());     media.parse();     toast.maketext(this, "le media dure : "+media.getduration(), toast.length_short).show();    // toast.maketext(this, "le media dure : "+media., toast.length_short).show();     mmediaplayer.setmedia(media);     //mmediaplayer.setvideotrackenabled(true);     //media.release();    // mmediaplayer.setequalizer(vlcoptions.getequalizer());    // mmediaplayer.setvideotitledisplay(mediaplayer.position.disable, 0);     int sw = getwindow().getdecorview().getwidth();     int sh = getwindow().getdecorview().getheight();     vlcinstance.get().setwindowsize(sw, sh);     mmediaplayer.play();     toast.maketext(this, "le player une valeur de : "+mmediaplayer.isplaying(), toast.length_short).show();    // media.parse();    // media.release();    // mmediaplayer.setmedia(media);    // mmediaplayer.play(); }  private final surfaceholder.callback msurfacecallback = new surfaceholder.callback() {     @override     public void surfacechanged(surfaceholder holder, int format, int width, int height) {         if(mediaplayer() != null) {             width = 100;             height =100;             toast.maketext(getapplicationcontext(), "surface width = "+width, toast.length_short).show();             toast.maketext(getapplicationcontext(), "surface height = "+height, toast.length_short).show();             final surface newsurface = holder.getsurface();             if (msurface != newsurface) {                 msurface = newsurface;                 toast.maketext(getapplicationcontext(), "surfacechanged: " + msurface, toast.length_short).show();                 libvlc().attachsurface(msurface, videoplayeractivity.this);                 msurfaceready = true;                 startvideo();                 //mhandler.sendemptymessage(1);             }         }     }      @override     public void surfacecreated(surfaceholder holder) {     }      @override     public void surfacedestroyed(surfaceholder holder) {         log.i(tag, "surfacedestroyed");         if(mediaplayer() != null) {             msurface = null;             libvlc().detachsurface();             msurfaceready = false;         }     } };  private final handler mhandler = new videoplayerhandler(this);  private static class videoplayerhandler extends weakhandler<videoplayeractivity> {     public videoplayerhandler(videoplayeractivity owner) {         super(owner);     }      @override     public void handlemessage(message msg) {         videoplayeractivity activity = getowner();         if(activity == null) // weakreference gc'ed             return;          switch (msg.what) {             case 1:                 activity.startvideo();                 break;             default:                 break;         }     } };  public static void start(context context, uri uri) {     start(context, uri, null, false, -1); }  public static void start(context context, uri uri, boolean fromstart) {     start(context, uri, null, fromstart, -1); }  public static void start(context context, uri uri, string title) {     start(context, uri, title, false, -1); }  private static void start(context context, uri uri, string title, boolean fromstart, int openedposition) {     intent intent = new intent(context, videoplayeractivity.class);       intent.setaction(play_from_videogrid);     intent.putextra(play_extra_item_location, uri);     intent.putextra(play_extra_item_title, title);     intent.putextra(play_extra_from_start, fromstart);     intent.putextra(play_extra_opened_position, openedposition);      /*if (openedposition != -1)         intent.addflags(intent.flag_activity_new_task | intent.flag_activity_multiple_task);*/     toast.maketext(context, "uri = "+uri.tostring(), toast.length_short).show();     context.startactivity(intent);  // /!\ start activity /!\ !!! }  @override public void showaudiodelaysetting() {  }  @override public void showsubsdelaysetting() {  }  @override public void enddelaysetting() {  }  @override public boolean onsingletapconfirmed(motionevent motionevent) {     return false; }  @override public boolean ondoubletap(motionevent motionevent) {     return false; }  @override public boolean ondoubletapevent(motionevent motionevent) {     return false; } } 

to start videoplayeractivity call start(context context, uri uri) , creat activity.

to resum code :

after oncreat() call onresum() call msurfaceholder.addcallback(msurfacecallback); , callback call startvideo() should start video, nothing start..

so if have sample of how create simple video player last libvlc or idea fail, helpful

please see below sample repo created. doesn't have bells , whistles, plays valid video url. uses vlc sdk kindly provided mrmaffen:

https://github.com/gareoke/vlcplayer


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -