2017-04-07 8 views
1

저는 지원되는 비디오 캡처 응용 프로그램을 제작하고 있지만 비디오를 캡처하고 해당 비디오를 캡처하여 기본 카메라 폴더에 저장하지만 그 결과 코드는 -1입니다. 다음 코드를 사용하고 있습니다.누우 가트 (Nougat)에서의 비디오 캡쳐?

public void startRecordingVideo() { 
    if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) { 
     Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
     File mediaFile = new File(
       Environment.getExternalStorageDirectory().getAbsolutePath() + "/myvideo.mp4"); 
     videoUri = Uri.fromFile(mediaFile); 
     //intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); 
     startActivityForResult(intent, VIDEO_CAPTURE); 
    } else { 
     Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show(); 
    } 
} 

내가 여기 처음

if (requestCode == VIDEO_CAPTURE) { 
      //if (resultCode == RESULT_OK) { 
       int width = 0, DisplayWidth = 0; 
       //int height = 0, DisplayHeight = 0; 
       if (new File(Constants.APP_PATH + "/myvideo1.mp4").exists()) { 
        MediaMetadataRetriever retriever = new MediaMetadataRetriever(); 
        retriever.setDataSource(Constants.APP_PATH + "/myvideo1.mp4"); 
        Bitmap bmp = retriever.getFrameAtTime(); 
        width = bmp.getHeight(); 

        VideoPath = Constants.APP_PATH + "/myvideo1.mp4"; 
        DisplayMetrics displaymetrics = new DisplayMetrics(); 
        MainActivity.this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
        DisplayWidth = displaymetrics.widthPixels; 
        String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); 
        int VideoDuration = Integer.parseInt(time); 
        if (width >= DisplayWidth * 1.5 && VideoDuration <= Constants.VIDEO_UPPER_LIMIT) { 
         new ResizeVideoTask(VideoPath).execute(); 
        } else if (VideoDuration > Constants.VIDEO_UPPER_LIMIT) { 
         showTimeDialog(); 
        } else { 
         File afile = new File(VideoPath); 
         String path = Constants.APP_PATH + "/myvideo.mp4"; 
         File destfile = new File(path); 
         if (destfile.exists()) { 
          destfile.delete(); 
         } 
         copyFile(new FileInputStream(afile),new FileOutputStream(destfile)); 
         Intent switchIntent = new Intent(MainActivity.this,VideoActivity.class); 
         switchIntent.putExtra("URI", Uri.fromFile(destfile).toString()); 
         switchIntent.putExtra("FILE_PATH", path); 
         startActivity(switchIntent); 
        } 
        retriever.release(); 
       } 
      } else if (resultCode == RESULT_CANCELED) { 

      } else { 

      //} 
     } 
+0

결과는 ['RESULT_OK'] (https://developer.android.com/reference/android/app/Activity.html#RESULT_OK)입니다. 왜 이것이 문제입니까? – CommonsWare

+0

제거하고 시도해 보겠지만 동영상 및 경로가 나에게 돌아 오지 않으며 오류가 발생하지 않습니다. – Kuldeep

+0

그러면 질문을 편집하고 ** 문제가있는 ** ** 당신의 onActivityResult() 메소드와 당신이 상상하고있는'Uri' ("path"가 아닌)를 어떻게 사용하는지 보여줘야합니다 돌아 오기. – CommonsWare

답변

0

내 onActivityResult를 코드를 걸었습니다, 당신은 ACTION_VIDEO_CAPTUREIntentEXTRA_OUTPUT을 통과하지 않았다. 결과적으로 카메라 앱은 동영상을 저장할 위치를 선택하고 을 통해 UrionActivityResult()에게 전달합니다. 당신은 그것을 사용하지 않습니다. 당신이 당신의 intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); 라인 (전항의 문제를 해결하기 위해) 주석을 제거하면

둘째는, 여기에 사용하는 videoUri는 다르게 당신이 onActivityResult()에서 사용하고 무엇보다 정의된다.

+0

고마워 친구지만 이미 시도했지만 결과 코드는 -1이고 의도 데이터 = null은 nougat에서 나에게 돌아갑니다. – Kuldeep

+0

@ Kuldeep : "그것이 무엇"인지 모르겠습니다. 'EXTRA_OUTPUT'을 가지고 있지 않고 카메라 앱이'Uri'을 돌려주지 않는다면, 당신은 버그가있는 카메라 앱으로 작업하고 있습니다. 이제'EXTRA_OUTPUT'을 포함하고 있다면,'Uri'이'onActivityResult()'에서 여러분에게 반환되지는 않을 것입니다. 그러나 비디오가 어디에 기록되어야하는지 알 것입니다. – CommonsWare

+0

고마워,하지만 내 흐름이 바뀌고, mannually 카메라를 만들고 비디오 및 그 작업을 잘하고 더 잘 캡처하고 있습니다. 이유 : 나는 어떤 반환 uri 및 결과도 얻지 않으며 이렇게 이것을 바꾼다. 고마워요. 중요한 시간을 주셔서 감사합니다. – Kuldeep