我正在我的应用程序中启动相机应用程序并录制视频。录制后,我也将其保存在 SD 卡上。问题是图库中的视频可以播放,而SD卡上的视频无法播放。
private void recordVideo() {
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
startActivityForResult(intent, CAMERA_VID_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if ( requestCode == CAMERA_VID_REQUEST && resultCode == Activity.RESULT_OK) {
try {
AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(data.getData(), "r");
FileInputStream fis = videoAsset.createInputStream();
File videoFile = new File(Environment.getExternalStorageDirectory().getPath()+"/test.mp4");
FileOutputStream fos = new FileOutputStream(videoFile);
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
fis.close();
fos.close();
} catch (IOException e) {
// TODO: handle error
}
}
在两个不同的设备上试过。任何有助于解决此问题的解决方案?