에 대한
@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번째) 대신 밀리 초 소요, 귀하의 경우를 너무 항상 첫 번째 프레임으로 반올림됩니다.
이 질문에 왜 네거티브가 주어지는 지 이해할 수 없습니까? 문제가 어디 있습니까? 내가 할 수있는 한 문제가 있고 세부 정보를 제공합니다. – hosein
은 http://stackoverflow.com/a/24307619/3496570을 참조해야합니다. – Nepster