2016-03-07 88 views

回答

-2

試試這個,

private static File getOutputMediaFile(int type){ 

     // Check that the SDCard is mounted 
     File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES), "MyCameraVideo"); 


     // Create the storage directory(MyCameraVideo) if it does not exist 
     if (! mediaStorageDir.exists()){ 

      if (! mediaStorageDir.mkdirs()){ 

       output.setText("Failed to create directory MyCameraVideo."); 

       Toast.makeText(ActivityContext, "Failed to create directory MyCameraVideo.", 
         Toast.LENGTH_LONG).show(); 

       Log.d("MyCameraVideo", "Failed to create directory MyCameraVideo."); 
       return null; 
      } 
     } 


     // Create a media file name 

     // For unique file name appending current timeStamp with file name 
     java.util.Date date= new java.util.Date(); 
     String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") 
          .format(date.getTime()); 

     File mediaFile; 

     if(type == MEDIA_TYPE_VIDEO) { 

      // For unique video file name appending current timeStamp with file name 
      mediaFile = new File(mediaStorageDir.getPath() + File.separator + 
      "VID_"+ timeStamp + ".mp4"); 

     } else { 
      return null; 
     } 

     return mediaFile; 
    } 

點擊此鏈接,供大家參考,這個鏈接將幫助您存儲在離子科爾多瓦外部SD卡的視頻文件。

http://androidexample.com/Camera_Video_Capture_And_Save_On_SDCard_-_Android_Example/index.php?view=article_discription&aid=123

我希望你能很快解決問題。