0

アプリケーションでカメラアプリを起動し、ビデオを録画しています。録音後、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           
             }
        }

2つの異なるデバイスで試してみました。この問題を解決するのに役立つ解決策はありますか?

4

0 に答える 0