Skip to content

Instantly share code, notes, and snippets.

@yeshengwu
Created March 21, 2019 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeshengwu/5bc9d8c30f78c9ed76a249f6d7d584a4 to your computer and use it in GitHub Desktop.
Save yeshengwu/5bc9d8c30f78c9ed76a249f6d7d584a4 to your computer and use it in GitHub Desktop.
private Context mContext;
public void setContext(Context context) {
mContext = context;
createfile();
}
private BufferedOutputStream outputStream;
private void createfile() {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + SystemClock.elapsedRealtime() + ".h264";
File file = null;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File file1 = mContext.getApplicationContext().getExternalCacheDir();
if (file1 != null) {
file1 = FileUtils.getFile(file1, "test");
file1.mkdirs();
file = FileUtils.getFile(file1, 1 + ".h264");
Log.e("evan", "filepateh=" + file.getAbsolutePath());
}
}
if (file.exists()) {
file.delete();
}
try {
outputStream = new BufferedOutputStream(new FileOutputStream(file));
} catch (Exception e) {
e.printStackTrace();
}
}
try {
Log.e("evan","onVideoPacket. packet = "+packet.size);
outputStream.write(packet.data, 0, packet.size);
} catch (IOException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment