2014-10-14 10 views
2

아래 코드는 (test.gif) 첫 번째 프레임 만 반환하고 동일한 프레임 5 개 (비디오 첫 번째 프레임)를 gif로 만듭니다.MediaMetadataRetriever getFrameAtTime 첫 번째 프레임 만 반환

StackOverflow에서 대부분의 질문을 읽었지만이 문제의 원인을 파악할 수 없습니다.

또한 제안에 따라 옵션을 사용하여 mmRetriever.getFrameAtTime을 사용하려고 시도했지만 성공하지 못했습니다. this 원에서 5000

+1

이 질문에 왜 네거티브가 주어지는 지 이해할 수 없습니까? 문제가 어디 있습니까? 내가 할 수있는 한 문제가 있고 세부 정보를 제공합니다. – hosein

+0

은 http://stackoverflow.com/a/24307619/3496570을 참조해야합니다. – Nepster

답변

1

에 대한

@Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (resultCode == RESULT_OK) { 

      Uri vid = data.getData(); 
      videoPath = getPath(vid); 

      MediaMetadataRetriever mmRetriever = new MediaMetadataRetriever(); 
      mmRetriever.setDataSource(videoPath); 
      String METADATA_KEY_DURATION = mmRetriever 
        .extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); 


      ByteArrayOutputStream bos = new ByteArrayOutputStream(); 

      AnimatedGifEncoder encoder = new AnimatedGifEncoder(); 
      encoder.setDelay(30); 
      encoder.start(bos); 

      int max = (int) Long.parseLong(METADATA_KEY_DURATION); 
      Log.i("max",String.valueOf(max)); 
      for (int i=1000000;i<max*1000;i+=1000000) { 
       Log.i("i",String.valueOf(i)); 

       Bitmap bitmap = mmRetriever.getFrameAtTime(i,MediaMetadataRetriever.OPTION_CLOSEST); 

       encoder.addFrame(bitmap); 


      } 
      encoder.finish(); 
      try { 
       String filepath = Environment.getExternalStorageDirectory() 
         + File.separator + "test.gif"; 
       FileOutputStream outStream = new FileOutputStream(filepath); 
       outStream.write(bos.toByteArray()); 
       outStream.close(); 
       GifAnimationDrawable big = new GifAnimationDrawable(
         new FileInputStream(filepath)); 

       imageview.setImageDrawable(big); 
       big.setVisible(true, true); 

      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

     } 

    } 

로그인 반환 최대 값 :

MediaMetadataRetriever의 getFrameAt 방법은 마이크로 초 (1/1,000,000번째) 대신 밀리 초 소요, 귀하의 경우를 너무 항상 첫 번째 프레임으로 반올림됩니다.

+0

코드를 다음과 같이 업데이트하십시오. for (int i = 1000000; i hosein

+0

윌리엄,이게 무슨 뜻인지, 로그를 사용하고 나는 10000002000000과 같습니다. 각 단계마다 is't 옳은? – hosein

+0

William,하지만 작동하지 않습니다. 시도해 보셨습니까? – hosein