I'm trying to display a set of Bitmaps using an AnimationDrawable
object. For some reason, some of the images are missing when the view is rendered in the UI:
...
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(mContext, videoUri);
...
AnimationDrawable frameAnimation = new AnimationDrawable();
for(int i=0; i < numberOfFrames; i++) {
Bitmap frame = retriever.getFrameAtTime(i * 500 * 1000); // get 2 frames per second
frameAnimation.addFrame(new BitmapDrawable(getResources(), frame), 100); //
}
...
frameAnimation.setOneShot(false);
frameAnimation.start();
Calling frameAnimation.getNumberOfFrames()
returns the correct number of frames (say 4
for a 2 second clip).
The problem is frameAnimation.start()
only shows a subset of those frames in the UI (for instance frameAnimation
could have 17 frames and only play through 4 of them).
Any ideas why the AnimationDrawable
object is missing Bitmaps when looping through its frames?
Thanks!