Thursday, September 22, 2011

[android-developers] MediaMetatdataRetriever Issue

I'm using the following snippet  within a class's onCreate  that extends  ImageView

            MediaMetadataRetriever  retrieve = new MediaMetadataRetriever();
            retrieve.setDataSource(name);
            long Duration = Long.parseLong(retrieve.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));

            for (int frame = 0; frame < Duration; frame += 300)  {
                parent.removeAllViews();
                Bitmap  pict = retrieve.getFrameAtTime(frame);
Log.e("Media" , "Video Loading    " + frame);               
                Matrix matrix = new Matrix();
                float scale = 680.0f / pict.getHeight();
                matrix.postScale(scale, scale);
                Bitmap image = Bitmap.createBitmap(pict, 0, 0, pict.getWidth(), pict.getHeight(), matrix, true);
                layers[1] = new BitmapDrawable(mBitmap);            layers[1].setAlpha(255);
                layers[0] = new BitmapDrawable(image);                 layers[0].setAlpha(255);
                LayerDrawable layerDraw = new LayerDrawable(layers);
                super.setImageDrawable(layerDraw);
               
                parent.setBackgroundColor(Color.BLACK);
                parent.addView(this , new LayoutParams(LayoutParams.FILL_PARENT , LayoutParams.FILL_PARENT));
            }
Log.e("Media" , "Video LoadED    ");               
           
What I can't understand is that is runs through the loop fine,  but it only shows the  first frame ?

parent is the FrameLayout within which the  ImageView is to be shown .

Can anyone shed light on this

Thanks in advance ?


No comments:

Post a Comment