Video capture with background audio on Android -


i trying create app record videos playing background music. expected output captured video above mentioned music.

i not sure whether rubbish question but, please suggest idea capture video background audio on android?

my solution fine, try it:

service android:

import java.util.calendar;  import android.app.service; import android.content.context; import android.content.intent; import android.graphics.pixelformat; import android.hardware.camera; import android.hardware.camera.camerainfo; import android.media.camcorderprofile; import android.media.mediarecorder; import android.os.bundle; import android.os.handler; import android.os.ibinder; import android.view.gravity; import android.view.surfaceholder; import android.view.surfaceview; import android.view.windowmanager; import android.view.windowmanager.layoutparams;  public class backgroundvideorecorder extends service implements surfaceholder.callback {  private windowmanager windowmanager; private surfaceview surfaceview; private camera camera = null; private mediarecorder mediarecorder = null;    int conttime = 0, duracaogravacao = 30; //interval  in seconds record video  private class thread implements runnable { public void run() {      conttime++;      if (conttime >= duracaogravacao) {         stopservice();     }      tick_handler.postdelayed(tick_thread, 1000); } }  handler tick_handler; thread tick_thread;  preferences pref;  @override public void oncreate() {  windowmanager = (windowmanager)         .getsystemservice(context.window_service); surfaceview = new surfaceview(this); layoutparams layoutparams = new windowmanager.layoutparams(1, 1,         windowmanager.layoutparams.type_system_overlay,         windowmanager.layoutparams.flag_watch_outside_touch,         pixelformat.translucent); layoutparams.gravity = gravity.left | gravity.top; windowmanager.addview(surfaceview, layoutparams);  surfaceview.getholder().addcallback(this);  tick_handler = new handler(); tick_thread = new thread();  video_recorder_folder = new _path().getpathvideo();  }  @override public void onstart(intent intent, int startid) {  tick_handler.post(tick_thread);  }  // method called right after surface created (initializing , starting // mediarecorder) @override public void surfacecreated(surfaceholder surfaceholder) {  boolean found = false;  int = 0;  try {     (i = 0; < camera.getnumberofcameras(); i++) {          camera.camerainfo newinfo = new camera.camerainfo();          camera.getcamerainfo(i, newinfo);          if (newinfo.facing == camerainfo.camera_facing_front) {             found = true;             break;         }     } } catch (exception e) {     e.printstacktrace(); }  if (found) {     camera = camera.open(i); } else {     camera = camera.open(); }  calendar lcdatetime = calendar.getinstance();  string t = string.valueof(lcdatetime.gettimeinmillis());  nomearquivo = "hire_me_now_" + t + ".mp4";  nomearquivo = nomearquivo.replace(" ", "_").replace(":", "_")         .replace("-", "_");  string caminhoarquivo = video_recorder_folder + "/" + nomearquivo;  mediarecorder = new mediarecorder(); camera.unlock();  mediarecorder.setpreviewdisplay(surfaceholder.getsurface()); mediarecorder.setcamera(camera); mediarecorder.setaudiosource(mediarecorder.audiosource.camcorder); mediarecorder.setvideosource(mediarecorder.videosource.camera); mediarecorder.setprofile(camcorderprofile         .get(camcorderprofile.quality_qvga)); mediarecorder.setvideoframerate(15);  mediarecorder.setoutputfile(caminhoarquivo);  try {     mediarecorder.prepare();  } catch (exception e) {     e.printstacktrace(); }  mediarecorder.start(); }  // stop recording , remove surfaceview @override public void ondestroy() {  mediarecorder.stop(); mediarecorder.reset(); mediarecorder.release();  camera.lock(); camera.release();  windowmanager.removeview(surfaceview);  }  protected void stopservice() { try {     this.stopself(); } catch (exception e) {     e.printstacktrace(); } }  @override public void surfacechanged(surfaceholder surfaceholder, int format,     int width, int height) { }  @override public void surfacedestroyed(surfaceholder surfaceholder) { }  @override public ibinder onbind(intent intent) { return null; } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -