Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当.3gp文件转换为.zip文件时,ProgressDialog不显示_Android_Progressdialog_Android Videoview - Fatal编程技术网

Android 当.3gp文件转换为.zip文件时,ProgressDialog不显示

Android 当.3gp文件转换为.zip文件时,ProgressDialog不显示,android,progressdialog,android-videoview,Android,Progressdialog,Android Videoview,我正在开发Android应用程序 当我点击按钮时,我需要显示一个进度对话框 在该按钮中,我将视频文件转换为.zip文件并计算该文件的大小。 在此过程中,我需要显示ProgressDialog,但它没有显示 屏幕在计算时被击中,计算后显示ProgressDialog,然后屏幕导航到下一个屏幕 我的代码: save.setOnClickListener(new View.OnClickListener() { @Override public void on

我正在开发Android应用程序

当我点击按钮时,我需要显示一个进度对话框

在该按钮中,我将视频文件转换为.zip文件并计算该文件的大小。 在此过程中,我需要显示ProgressDialog,但它没有显示

屏幕在计算时被击中,计算后显示ProgressDialog,然后屏幕导航到下一个屏幕

我的代码:

    save.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
                    MediaCheck.this.runOnUiThread(new Runnable() {
                        public void run() {
                    pd = ProgressDialog.show(MediaCheck.this, "",
                                    "Checking the video compatability. Please wait", true);
                        }
                    });
                    video_Path= makeZip(video_Path);
                    if (video_Path.equalsIgnoreCase("File size is too large")) {
                        pd.dismiss();
                        Toast.makeText(getApplicationContext(),
                                "Large video", Toast.LENGTH_LONG)
                                .show();
                        return;
                    }
pd.dismiss();       
// Doing screen navigation here.
        }
    });
编码以制作拉链并知道其大小

private static String makeZip(String videoPath) {
    byte[] buffer = new byte[1024];
    String[] videoFileName = videoPath.split("/");
    File directory = null;
    try {
        ContextWrapper cw = new ContextWrapper(context_this);
        // path to /data/data/yourapp/app_data/imageDir
        directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
        FileOutputStream fos = new FileOutputStream(directory
                + "/IRCMS_Video.zip");
        ZipOutputStream zos = new ZipOutputStream(fos);
        ZipEntry ze = null;
        ze = new ZipEntry(videoFileName[5]);
        zos.putNextEntry(ze);
        FileInputStream in = new FileInputStream(videoPath);

        int len;

        while ((len = in.read(buffer)) > 0) {
            zos.write(buffer, 0, len);
        }
        File videoZip = new File(directory + "/IRCMS_Video.zip");
        videoLength = videoZip.length() / (1024 * 1024);
        if (videoLength > 3)
            return "File size is too large";
        in.close();
        zos.closeEntry();

        // remember close it
        zos.close();

        System.out.println("Done");

    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return directory.toString() + "/IRCMS_Video.zip";

}
}

请帮助…

然后您应该尝试
ASYNCTASK
以轻松执行您的操作并降低使用线程的复杂性

private class Converter extends AsyncTask<String, Void, Void> { //Converter is class name
     protected String doInBackground(String... urls) {
         //THIS METHOD WILL BE CALLED AFTER ONPREEXECUTE
         //YOUR NETWORK OPERATION HERE
         return null;
     }

     protected void onPreExecute() {
         super.onPreExecute();
         //THIS METHOD WILL BE CALLED FIRST
         //DO OPERATION LIKE SHOWING PROGRESS DIALOG PRIOR TO BEGIN NETWORK OPERATION
     }

     protected void onPostExecute(String result) {
         super.onPostExecute();
         //TNIS METHOD WILL BE CALLED AT LAST AFTER DOINBACKGROUND
         //DO OPERATION LIKE UPDATING UI HERE
     }
 }
私有类转换器扩展异步任务{//Converter是类名
受保护的字符串doInBackground(字符串…URL){
//此方法将在ONPREEXECUTE之后调用
//你的网络运作在这里
返回null;
}
受保护的void onPreExecute(){
super.onPreExecute();
//将首先调用此方法
//在开始网络操作之前,执行诸如显示进度对话框之类的操作
}
受保护的void onPostExecute(字符串结果){
super.onPostExecute();
//TNIS方法将在DOINBACKGROUND之后最后被调用
//在这里执行更新UI之类的操作
}
}

在UI线程挂起应用程序之前,您正在对其进行计算。在背景线程上进行计算。您可以通过以下方式解决此问题:-

save.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                pd = ProgressDialog.show(MediaCheck.this, "",
                        "Checking the video compatability. Please wait", true);
                Thread background = new Thread(new Runnable() {

                    public void run() {
                        // TODO Auto-generated method stub
                        video_Path= makeZip(video_Path);

                        MediaCheck.this.runOnUiThread(new Runnable() 
                        {
                            public void run() 
                            {

                                if (video_Path.equalsIgnoreCase("File size is too large")) {
                                    pd.dismiss();
                                    Toast.makeText(getApplicationContext(),
                                            "Large video", Toast.LENGTH_LONG)
                                            .show();
                                    pd.dismiss();  
                                    return;
                                }
                            }
                        });
                    }
                });
                background.start();
                // Doing screen navigation here.
            }
        });

我写了ProgressDialog.show(MediaCheck.this,“,…)请看一次。就连我也试过了,但没有成功。高拉夫·贝里有一个恰当的答案。用户2085985,永远不要在UI线程中执行长时间的操作,因为你会卡住你的应用程序并触发ANR。