android - Why I can't play video when I set maxDuration -


i made camera records video when it's opened. problem when put maxduration (3 sec) stops recording after 3 seconds video can not played. how fix that. when delete recorder.setmaxduration(3000); records , stops recording after exit app , video works, when put maxduration 3sec doesn't play video.

import android.annotation.suppresslint; import android.annotation.targetapi; import android.content.context; import android.hardware.camera; import android.media.mediarecorder; import android.os.environment; import android.util.attributeset; import android.view.surfaceholder; import android.view.surfaceview;  /**  * created admin on 3.10.2015.  */ public class videocapture extends surfaceview implements surfaceholder.callback {      private mediarecorder recorder;     private surfaceholder holder;     public context context;     private camera camera;     public static string videopath = environment.getexternalstoragedirectory()             .getpath() +"/your_video.mp4";      public videocapture(context context) {         super(context);         this.context = context;         init();     }      public videocapture(context context, attributeset attrs) {         super(context, attrs);         init();     }      public videocapture(context context, attributeset attrs, int defstyle) {         super(context, attrs, defstyle);         init();     }      @suppresslint("newapi")     public void init() {         try {             recorder = new mediarecorder();             holder = getholder();             holder.addcallback(this);             holder.settype(surfaceholder.surface_type_push_buffers);             camera = getcamerainstance();             if(android.os.build.version.sdk_int > 7)                 camera.setdisplayorientation(90);             camera.unlock();             recorder.setcamera(camera);             recorder.setvideosource(mediarecorder.videosource.default);             recorder.setoutputformat(mediarecorder.outputformat.mpeg_4);             recorder.setmaxduration(3000);              recorder.setvideoencoder(mediarecorder.videoencoder.mpeg_4_sp);             recorder.setoutputfile(videopath);         } catch (exception e) {             e.printstacktrace();         }     }      public void surfacechanged(surfaceholder arg0, int arg1, int arg2, int arg3) {     }      public void surfacecreated(surfaceholder mholder) {         try {             recorder.setpreviewdisplay(mholder.getsurface());             recorder.prepare();             recorder.start();         } catch (exception e) {             e.printstacktrace();         }     }      public void stopcapturingvideo() {         try {             recorder.stop();             camera.lock();         } catch (exception e) {             e.printstacktrace();         }     }      @targetapi(5)     public void surfacedestroyed(surfaceholder arg0) {         if (recorder != null) {             stopcapturingvideo();             recorder.release();             camera.lock();             camera.release();             recorder = null;         }     }      private camera getcamerainstance() {         camera c = null;         try {             c = camera.open(); // attempt camera instance         } catch (exception e) {             // camera not available (in use or not exist)         }         return c;     } } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -