我有一个函数名CreateVideo()
,问题是:
以下是代码:
private class MyVideo extends AsyncTask<Void, Void, String> {
private Context context;
private String output;
private String quality;
private FramePackage framePackage;
CreateMP4Video createMP4Video;
public MyVideo(Context context, FramePackage framePackage, String output, String quality) {
// TODO Auto-generated constructor stub
this.context = context;
this.output = output;
this.quality = quality;
this.framePackage = framePackage;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create Video Maker
createMP4Video = new CreateMP4Video(context, framePackage, output, quality);
// Create progress
mProgress = new ProgressDialog(MainActivity.this);
mProgress.setTitle("Please Wait..");
mProgress.setMessage("Creating Video...");
mProgress.setProgressStyle(mProgress.STYLE_HORIZONTAL);
mProgress.setProgress(0);
// set Max = total number of frame
mProgress.setMax(framePackage.getCount());
mProgress.setCancelable(false);
mProgress.show();
};
@Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
createMP4Video.CreateVideo();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
while (mProgress.getProgress() <= mProgress.getMax()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
updateBarHandler.post(new Runnable() {
public void run() {
// get the current frame (frame 1, 2, 3,...)
// that already added to video
// In thist case, it always get the last frame
// progress bar run from 0% to 100% directly
mProgress.setProgress(createMP4Video.getCurrentFrame());
}
});
if (mProgress.getProgress() == mProgress.getMax()) {
mProgress.dismiss();
}
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Toast.makeText(context, result, Toast.LENGTH_SHORT).show();
}
}
提前谢谢!
答案 0 :(得分:0)
将onprogress对话框放在onPreExecute()方法中,就像你已经完成的那样
//创建进度
mProgress = new ProgressDialog(MainActivity.this);
mProgress.setTitle("Please Wait..");
mProgress.setMessage("Creating Video...");
mProgress.setProgressStyle(mProgress.STYLE_HORIZONTAL);
mProgress.setProgress(0);
// set Max = total number of frame
mProgress.setMax(framePackage.getCount());
mProgress.setCancelable(false);
mProgress.show();
取消onPostExecute
中的对话框您可以查看progressupdate示例ONPROGRESS UPDATE