How to pause/resume the video recording

天涯浪子 提交于 2020-01-02 19:48:40

问题


I want to implement pause/resume functionality while recording video. MediaRecorder is not having any method for pause/resume. Native camera application is having pause/resume feature. Is it possible to implement it?

Please guide me. Any help or guidance will be well appreciated.


回答1:


Finally i find the answer :) i research about ffmpeg it seems more deeply and some more days digging around it but can't get proper resource for ffmepg and i try to use mp4parser lib and successfully completed my requirement.

Code For Merging Multiple Video

public class MergeVide extends AsyncTask<String, Integer, String> {

@Override
protected void onPreExecute() {
    progressDialog = ProgressDialog.show(Video.this,
            "Preparing for upload", "Please wait...", true);
    // do initialization of required objects objects here
};

@Override
protected String doInBackground(String... params) {
    try {
        String paths[] = new String[count];
        Movie[] inMovies = new Movie[count];
        for (int i = 0; i < count; i++) {
            paths[i] = path + filename + String.valueOf(i + 1) + ".mp4";
            inMovies[i] = MovieCreator.build(new FileInputStream(
                    paths[i]).getChannel());
        }
        List<Track> videoTracks = new LinkedList<Track>();
        List<Track> audioTracks = new LinkedList<Track>();
        for (Movie m : inMovies) {
            for (Track t : m.getTracks()) {
                if (t.getHandler().equals("soun")) {
                    audioTracks.add(t);
                }
                if (t.getHandler().equals("vide")) {
                    videoTracks.add(t);
                }
            }
        }

        Movie result = new Movie();

        if (audioTracks.size() > 0) {
            result.addTrack(new AppendTrack(audioTracks
                    .toArray(new Track[audioTracks.size()])));
        }
        if (videoTracks.size() > 0) {
            result.addTrack(new AppendTrack(videoTracks
                    .toArray(new Track[videoTracks.size()])));
        }

        BasicContainer out = (BasicContainer) new DefaultMp4Builder()
                .build(result);

        @SuppressWarnings("resource")
        FileChannel fc = new RandomAccessFile(String.format(Environment
                .getExternalStorageDirectory() + "/wishbyvideo.mp4"),
                "rw").getChannel();
        out.writeContainer(fc);
        fc.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String mFileName = Environment.getExternalStorageDirectory()
            .getAbsolutePath();
    mFileName += "/wishbyvideo.mp4";
    filename = mFileName;
    return mFileName;
}

@Override
protected void onPostExecute(String value) {
    super.onPostExecute(value);
    progressDialog.dismiss();
    Intent i = new Intent(Video.this, VideoUpload.class);
    i.putExtra("videopath", value);
    i.putExtra("id", id);
    i.putExtra("name", name);
    i.putExtra("photo", photo);
    startActivity(i);
    finish();
    }
}

the count is nothing but video file count.

the above code for merge more video and send the final code to another activity in that i have decided to preview the video. before using above code make sure use mp4parser lib.



来源:https://stackoverflow.com/questions/26035547/how-to-pause-resume-the-video-recording

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!