I am trying to implement a simple VideoView that would play the Video
from the file system. The Video loads fine and plays just fine.
However, I would like to know when the Video finished playing so that
I can finish() the activity and resume with the next. Here is what I
have.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:id="@+id/videoPlayer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:keepScreenOn="true"
    android:orientation="vertical" >
    <VideoView
        android:id="@+id/videoView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>
The Activity is as below.

    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.videoplayer);

    videoView = (VideoView) findViewById(R.id.videoView);
    videoView.setOnCompletionListener(new
MediaPlayer.OnCompletionListener()
    {
        @Override
        public void onCompletion(MediaPlayer mp)
        {
            Intent result = new Intent();
            setResult(1, result);
            finish();
        }
    }); // video finish listener

    Intent intent = getIntent();

    // Receiving the Data
    String fileName = intent.getStringExtra("fileName");

    videoView.setVideoPath(fileName);
    videoView.setMediaController(new MediaController(this));
    videoView.requestFocus();
    videoView.start();}
I call this Activity from a different Activity. Here is that Activity
definition.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:id="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:keepScreenOn="true">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:contentDescription="@string/imageViewDescription" /
>
    </LinearLayout>
VideoPlayer Activity Class

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    setContentView(R.layout.imageplayer);

    imageView = (ImageView) findViewById(R.id.imageView);

    updateUI(new File("/sdcard/Test/Test.3gp");
}

public void updateUI(File file)
{
        if (file.getName().toLowerCase().endsWith(".jpg") ||
file.getName().toLowerCase().endsWith(".png"))
        {
            Bitmap myBitmap =
BitmapFactory.decodeFile(file.getAbsolutePath());

            imageView.setImageBitmap(myBitmap);
        }
        else if (file.getName().toLowerCase().endsWith(".3gp") ||
file.getName().toLowerCase().endsWith(".mp4"))
        {
            //Starting a new Intent
            Intent nextScreen = new Intent(getApplicationContext(),
VideoPlayer.class);

            //Sending data to another Activity
            nextScreen.putExtra("fileName", file.getAbsolutePath());

            released = false;

            startActivityForResult(nextScreen, resultCode);
        }
    }
}

public void onActivityResult(int requestCode, int resultCode, Intent
data)
{
    super.onActivityResult(requestCode, resultCode, data);
}
The onCompletion method is never called and the onActivityResult()
method in the caller of this Activity also is not called. I would like
to know what is wrong with this. I tried playing both '.3gp' and
'.mp4' files with the same result. Please help

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to