Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.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 加快doinbackground()进程_Android_Android Asynctask - Fatal编程技术网

Android 加快doinbackground()进程

Android 加快doinbackground()进程,android,android-asynctask,Android,Android Asynctask,我用这个代码把加密视频分成4部分 public class SplitVideoFile { private static String result; static ArrayList<String>update=new ArrayList<>(); public static String main(File file) { try { // File file = new File("C:/Documents/Despicable Me 2

我用这个代码把加密视频分成4部分

public class SplitVideoFile {
private static String result;
static  ArrayList<String>update=new ArrayList<>();
public static String main(File file) {

    try {
       // File file = new File("C:/Documents/Despicable Me 2 - Trailer (HD) - YouTube.mp4");//File read from Source folder to Split.
        if (file.exists()) {

            String videoFileName = file.getName().substring(0, file.getName().lastIndexOf(".")); // Name of the videoFile without extension
           // String path = Environment.getDataDirectory().getAbsolutePath().toString() + "/storage/emulated/0/Videointegrity";
            String path =  "/storage/emulated/0/Videointegrity";
          //  File myDir = new File(getFile, "folder");
            //myDir.mkdir();

            File splitFile = new File(path.concat("/").concat(videoFileName));//Destination folder to save.
            if (!splitFile.exists()) {
                splitFile.mkdirs();
                Log.d("Directory Created -> ", splitFile.getAbsolutePath());
            }

            int i = 01;// Files count starts from 1
            InputStream inputStream = new FileInputStream(file);
            String videoFile = splitFile.getAbsolutePath() +"/"+ String.format("%02d", i) +"_"+ file.getName();// Location to save the files which are Split from the original file.
            OutputStream outputStream = new FileOutputStream(videoFile);
            Log.d("File Created Location: ", videoFile);
            update.add("File Created Location: ".concat(videoFile));
            int totalPartsToSplit =4 ;// Total files to split.
            int splitSize = inputStream.available() / totalPartsToSplit;
            int streamSize = 0;
            int read = 0;
            while ((read = inputStream.read()) != -1) {

                if (splitSize == streamSize) {
                    if (i != totalPartsToSplit) {
                        i++;
                        String fileCount = String.format("%02d", i); // output will be 1 is 01, 2 is 02
                        videoFile = splitFile.getAbsolutePath() +"/"+ fileCount +"_"+ file.getName();
                        outputStream = new FileOutputStream(videoFile);
                        Log.d("File Created Location: ", videoFile);
                        streamSize = 0;
                    }
                }
                outputStream.write(read);
                streamSize++;
            }

            inputStream.close();
            outputStream.close();

            Log.d("Total files Split ->", String.valueOf(totalPartsToSplit));
        result="success";
        } else {
            System.err.println(file.getAbsolutePath() +" File Not Found.");
            result="failed";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
public ArrayList<String> getUpdate()
{
    return update;
}
即使它会分割视频,但这一过程也会花费太多时间。

我怎样才能加快速度呢。当我在preexecute方法中显示进度条时,用户似乎看到进度条很长时间,这是我不希望看到的。

您必须调试和检查占用时间最多的拆分代码视频拆分是时间消耗型任务,它取决于设备规格,如处理器,您无法通过代码处理此性能。您也可以尝试使用FFMPEG进行视频操作。检查
 protected String doInBackground(Void...arg0) {
        Log.d(TAG + " DoINBackGround", "On doInBackground...");
        File encvideo=new File(epath.getText().toString());
        SplitVideoFile split=new SplitVideoFile();
        String result=split.main(encvideo);
        publishProgress(1);
        return result;
    }