Pregunta

Is there a way to display a set of images sequentially with play back features? I was wondering if this is possible to be done on an imageview or videoview?

¿Fue útil?

Solución

In your Activity

Timer myTimer;
String image[]; // array of imagePath
private int imagePostion;


class MyTimerTask extends TimerTask {

        public void run() {
            try {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            if (++imagePostion == image.length) {
                                imagePostion = 0;
                            }
                             imgView.setImageBitmap(BitmapFactory.decodeFile(image[imagePostion]));

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

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

        }
    }
// change image every 2 seconds
public void startTimerTask() {
        MyTimerTask myTask = new MyTimerTask();
        myTimer = new Timer();
        myTimer.schedule(myTask, 0, 2000);

    }

@Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

                image = {} // fille array with filePath




    }


@Override
    public void onPause() {
        super.onPause();

        try {
            myTimer.cancel();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

// start slide show
@Override
    public void onResume() {
        super.onResume();
            startTimerTask(); // start slide show
        }

Otros consejos

You can use the ImageSwitcher control together with a timer.

I have achieved the pictures playback using a ViewPager and i have already answered this here on SO. Although i have used the following technique to switch fragments but you can inflate images in the fragment: You can check my answer on the following link:

How to automatically switch pages using viewPager and Timer

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top