Question

I want to play video after showing all image. My code for image play one by one every 10 sec is given below. I want to implement with this code a video also play means I have 5 image which are play one by one every 10 sec when 5 image show then a video play automatically and after completion of video image are again play. All images and video play in cycle.

Following is my code,

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.ViewFlipper;
 public class MainActivity extends Activity
 {
    private ViewFlipper myviewflipper;
    private float initialXpoint;
    @Override
    protected void onCreate(Bundle savedInstanceState)
 {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    myviewflipper = (ViewFlipper) findViewById(R.id.myflipper);
    myviewflipper.setAutoStart(true);
    myviewflipper.setFlipInterval(10000);
    myviewflipper.startFlipping();
   }
   @Override
   public boolean onTouchEvent(MotionEvent touchevent)
   {
      switch (touchevent.getAction())
     {
        case MotionEvent.ACTION_DOWN:
        initialXpoint = touchevent.getX();
        break;
        case MotionEvent.ACTION_UP:
        float finalX = touchevent.getX();
        if (initialXpoint > finalX)
           {
              if (myviewflipper.getDisplayedChild() == 1)
               break;
               myviewflipper.showNext();
           }
        else
          {
               if (myviewflipper.getDisplayedChild() == 0)
              break;
              myviewflipper.showPrevious();
          }
          break;
      }
       return false;
    }
 }

my xml fil-

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:orientation="vertical">
       <ViewFlipper
     android:id="@+id/myflipper"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
    android:gravity="center" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/a"/>
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/b" />
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/c" />
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/d" />
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/e" />

      </ViewFlipper>
     </LinearLayout>
Was it helpful?

Solution

You can use view switcher or ViewFlipper if your images are static that means they are predefined in xml.

ViewFlipper Sample

Or you can use Thread and Handler pattern

Idea: Take ImageView in xml , Take array of Images, First set 0th image to ImageView after 10 secs set 1st so on..., You can add image along with simple Animation we have in Android.

Sample

SO question

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top