暂停录制视频

时间:2013-06-15 21:40:01

标签: android mediarecorder

录制时如何暂停视频? 我读到Android不支持此功能,但三星Galaxy S3上的默认摄像头完美无缺。 三星是如何做到的?

1 个答案:

答案 0 :(得分:3)

Recorder没有暂停功能,你要做的就是录制多个视频并简单合并。

class merge_video 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();
        }
}

计数只是视频文件计数。

上面的代码用于合并更多视频并将最终代码发送到另一个活动,因为我决定预览视频。 在使用上面的代码之前,请确保使用mp4parser lib