我如何在我的自定义相机中添加暂停功能,因为android媒体录制器类没有暂停方法。目前我使用mp4Parse库来合并视频文件以实现暂停功能但合并后我的视频旋转这里是我的代码我正在使用mp4Parse android。
private class MergeVideos extends AsyncTask<String, Integer, String> {
//The working path where the video files are located
private String workingPath;
//The file names to merge
private ArrayList<String> videosToMerge;
//Dialog to show to the user
private ProgressDialog progressDialog;
private MergeVideos(String workingPath, ArrayList<String> videosToMerge) {
this.workingPath = workingPath;
this.videosToMerge = videosToMerge;
}
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(MainActivity.this,
"Merging videos", "Please wait...", true);
};
@Override
protected String doInBackground(String... params) {
int count = videosToMerge.size();
try {
Movie[] inMovies = new Movie[count];
for (int i = 0; i < count; i++) {
//File file = new File(workingPath, videosToMerge.get(i));
File file = new File( videosToMerge.get(i));
//File file = new File(videosToMerge.get(i));
if(file.exists()) {
FileInputStream fis = new FileInputStream(file);
FileChannel fc = fis.getChannel();
inMovies[i] = MovieCreator.build(fc);
fis.close();
fc.close();
}
}
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);
}
if (t.getHandler().equals("")) {
}
}
}
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()])));
}
IsoFile out = new DefaultMp4Builder()
.build(result);
//rotate video
out.getMovieBox().getMovieHeaderBox().setMatrix(ROTATE_90);
long timestamp=new Date().getTime();
String timestampS="" + timestamp;
File storagePath = new File(workingPath);
storagePath.mkdirs();
File myMovie = new File(storagePath, String.format("output-file-%s.mp4", timestampS));
FileOutputStream fos = new FileOutputStream(myMovie);
FileChannel fco = fos.getChannel();
fco.position(0);
out.getBox(fco);
fco.close();
fos.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 += "/output-file.mp4";
return mFileName;
}
@Override
protected void onPostExecute(String value) {
super.onPostExecute(value);
progressDialog.dismiss();
}
}
在Android自定义相机中添加暂停功能的最佳方法是什么?
答案 0 :(得分:1)
您好Zohaib我想提供一个Url作为参考,可能满足您的要求如下: