OR
使用缓存播放解码的输出流。
class VideoTask extends AsyncTask<String, Integer, String> {
File outfile;
File decfile; File decfileORI;
FileInputStream encfis;Cipher decipher;
FileOutputStream decfos;
int read;
CipherOutputStream cos;
public downloadpage that;
public VideoTask(downloadpage joinAsync)throws FileNotFoundException, NoSuchPaddingException, NoSuchAlgorithmException {
this.that=joinAsync;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
// Toast.makeText(that, "TASK STARTED", Toast.LENGTH_SHORT).show();
// Toast.makeText(that, "sdadasd "+ that.originalKey , Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(String... strings) {////////////////////////////////////////////////
try {
outfile = new File("/sdcard/bus_encode.mp4");//GET
decfile = new File("/sdcard/bus_FinisH.mp4");//DECODE AND GIVE
encfis = new FileInputStream(outfile);
decfos = new FileOutputStream(decfile);
decipher = Cipher.getInstance("AES");
decipher.init(Cipher.DECRYPT_MODE, that.originalKey);
cos = new CipherOutputStream(decfos, decipher);
// Toast.makeText(that, "length" + vid_size, Toast.LENGTH_SHORT).show();
int c=0;
byte[] b = new byte[8*1024];
while (((read = encfis.read(b)) != -1)&&(c<10000)) {//c mahdudiyat video
cos.write(b,0,read);
cos.flush();c++;
}
cos.close();
}catch (Exception e){}////////////////////////////////////////////////////////////
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
// Toast.makeText(that, "finished DECODING. enjoy :)", Toast.LENGTH_LONG).show();
that.GoToVid();
}
}