1

I would like to make a small video (about 4 seconds) repeat until webview finishes loading the desired URL in the background. Right now the video plays once, then a blank black screen comes up until the page loads. I'm still pretty new to this... Thanks in advance for any help! Sorry for the EDITED stuff, but it was necessary.

Here is my splash java

package com.EDITED;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.widget.VideoView;

public class Splash extends Activity implements OnCompletionListener
{
VideoView videoView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
VideoView video = (VideoView) findViewById(R.id.videoView);

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setLooping(true);
    }
});

video.setVideoPath("android.resource://com.EDITED/raw/" + R.raw.splash);
video.start();
}

@Override
public void onCompletion(MediaPlayer mp)
{
    Intent intent = new Intent(this, EDITEDActivity.class);
    startActivity(intent);
    finish();
}
}
Nikoli4
  • 11
  • 5

1 Answers1

0

Basicaly you create a AsyncTask to do the loading and onPostExecute(Long result) you stop the video.

Also to loop the video you can use this

public class Splash extends Activity implements OnCompletionListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    VideoView video = (VideoView) findViewById(R.id.videoView);

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.setLooping(true);
        }
    });

    video.setVideoPath("android.resource://com.EDITED/raw/" + R.raw.splash);
    video.start();
}

}
Community
  • 1
  • 1
bughi
  • 1,838
  • 1
  • 13
  • 24
  • When I try the code above for looping I get the error "Cannot make a static reference to the non static method..." This is what I kept seeing with the other methods I tried. What am I missing? – Nikoli4 May 27 '12 at 22:43
  • Never mind, I moved some stuff around and now the video is looping. Now, on to Async. – Nikoli4 May 28 '12 at 01:26
  • you were getting that error because that code belongs inside the `onCreate()` method, i should have mentioned that – bughi May 28 '12 at 17:19
  • Ok, I was wrong, it's not working. I got rid of the errors but only by removing most of the code, at which point the video didn't repeat, and then the webview part failed to load. haha. I'm sure it's because I'm putting the above code in the wrong spot, or not formatting it correctly. Where do I insert it? – Nikoli4 Jun 01 '12 at 05:42
  • I actually had that at oen point and it wouldn't work, but I think I figured it out. I had to add VideoView videoView; other wise I kept getting an error in the videoView.setOnPreparedListner part. What I have now is below. There are no errors, but now when I run the app it force closes. – Nikoli4 Jun 03 '12 at 06:00