【发布时间】:2015-08-23 06:16:01
【问题描述】:
我正在开发 android 应用程序,它以 mp4 格式录制视频并将其上传到服务器,然后其他用户可以观看该视频。
我的问题是 mp4 不支持我在应用中需要的流媒体,而是需要下载所有视频才能开始播放。
我搜索了这个问题,发现支持流媒体的 mp4 具有 faststart 属性,它将 moov atom 放在视频文件的开头。
我的问题是如果可以的话,如何在 android 中实现这一点?如果不能,我可以在服务器上做吗?如何做?
我录制视频的代码是:
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;
}
【问题讨论】: