I am developing android application that record a video in mp4 format and upload it to a server, then other users can view that video.
My problem is that the mp4 is not supporting streaming which I need in my app, instead it needs to download all the video to start playing it.
I googled the issue and I found that mp4 that supports streaming have the faststart property which is putting the moov atom in the beginning of the video file.
My question is how to achieve that in android if it can be?? if not can I do it in the server and how?
My code to record video is :
if (requestCode == REQUEST_VIDEO_CAPTURE ) {
try
{
Log.e("videopath","videopath");
AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(data.getData(), "r");
FileInputStream fis = videoAsset.createInputStream();
File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
if (!root.exists()) {
root.mkdirs();
}
File file;
file=new File(root,"android_"+System.currentTimeMillis()+".mp4" );
videoUri = Uri.fromFile(file);
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while ((len = fis.read(buf)) > 0) {
fos.write(buf, 0, len);
}
fis.close();
fos.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return;
}