2014-09-25 100 views
2

我想在錄製視頻時實現暫停/恢復功能。 MediaRecorder沒有任何暫停/恢復的方法。本機相機應用程序具有暫停/恢復功能。有沒有可能實現它?如何暫停/恢復視頻錄製

請指導我。任何幫助或指導將不勝感激。

回答

2

最後我找到了答案:) 我研究有關的FFmpeg似乎更深入,一些多天挖周圍,但不能得到ffmepg 適當的資源,我嘗試使用mp4parser lib和成功地完成了我的要求。

代碼對於合併多個視頻

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

計數無非是視頻文件的數量。

上述代碼用於合併更多視頻並將最終代碼發送到另一個活動,因爲我決定預覽該視頻。 使用上面的代碼之前請確保使用mp4parser lib。

+0

感謝您的回覆。但除手動連接視頻文件外,還有其他方法嗎? – 2014-09-25 11:13:16

+0

如果你接受上述answer.please投票並接受支持的答案 – 2014-09-25 11:17:15

+0

這不是一個好的解決方案,因爲它將花費2+分鐘合併2視頻總共約5分鐘... – 2015-06-02 03:25:34