setLooping don't work in my videoplayer
<p>I am a Android newbie. I want to design my personal videoplayer to play streaming music, so I use MediaPlayer and SurfaceView. The project plays streaming video successfully, but it can't be setloop. I have google many articles and read Android Developer. I can't figure out why mediaPlayer.setLooping(true) don't work here. Thanks^^</p>

<pre><code>mediaPlayer.reset();
mediaPlayer.setDataSource(videoUrl);
mediaPlayer.setLooping(true);
mediaPlayer.prepare();    
</code></pre>

<p>The code includes two parts: 1.Test_Videoplayer.java   2.Player.java</p>

<p>1.Test_Videoplayer.java</p>

<pre><code>public class Test_Videoplayer extends Activity {
private SurfaceView surfaceView;
private Button btnPause, btnPlayUrl, btnStop;
private SeekBar skbProgress;
private Player player;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    surfaceView = (SurfaceView) this.findViewById(R.id.surfaceView1);

    btnPlayUrl = (Button) this.findViewById(R.id.btnPlayUrl);
    btnPlayUrl.setOnClickListener(new ClickEvent());

    btnPause = (Button) this.findViewById(R.id.btnPause);
    btnPause.setOnClickListener(new ClickEvent());

    btnStop = (Button) this.findViewById(R.id.btnStop);
    btnStop.setOnClickListener(new ClickEvent());

    skbProgress = (SeekBar) this.findViewById(R.id.skbProgress);
    skbProgress.setOnSeekBarChangeListener(new SeekBarChangeEvent());

    player = new Player(surfaceView, skbProgress);

}

class ClickEvent implements OnClickListener {
    @Override
    public void onClick(View arg0) {
        if (arg0 == btnPause) {
            player.pause();
        } else if (arg0 == btnPlayUrl) {
            String url = "http://sites.google.com/site/ronforwork/Home/android-2/littleMonster.3gp";
            player.playUrl(url);
        } else if (arg0 == btnStop) {
            player.stop();
        }
    }
}

class SeekBarChangeEvent implements SeekBar.OnSeekBarChangeListener {
    int progress;

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
        this.progress = progress * player.mediaPlayer.getDuration()
                / seekBar.getMax();
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        player.mediaPlayer.seekTo(progress);
    }
}
</code></pre>

<p>}</p>

<p>2.Player.java &lt;-- here is mediaPlayer.setLooping(true)</p>

<pre><code>public class Player implements OnBufferingUpdateListener, OnCompletionListener,
    MediaPlayer.OnPreparedListener, SurfaceHolder.Callback {

private int videoWidth;
private int videoHeight;

public MediaPlayer mediaPlayer;

private SurfaceHolder surfaceHolder;
private SeekBar skbProgress;

private Timer mTimer = new Timer();

public Player(SurfaceView surfaceView, SeekBar skbProgress) {
    this.skbProgress = skbProgress;

    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mTimer.schedule(mTimerTask, 0, 1000);
}

TimerTask mTimerTask = new TimerTask() {
    @Override
    public void run() {
        if (mediaPlayer == null)
            return;
        if (mediaPlayer.isPlaying() &amp;&amp; skbProgress.isPressed() == false) {
            handleProgress.sendEmptyMessage(0);
        }
    }
};

Handler handleProgress = new Handler() {
    public void handleMessage(Message msg) {
        int position = mediaPlayer.getCurrentPosition();
        int duration = mediaPlayer.getDuration();

        if (duration &gt; 0) {
            long pos = skbProgress.getMax() * position / duration;
            skbProgress.setProgress((int) pos);
        }
    };
};

public void play() {
    mediaPlayer.start();
}

public void playUrl(String videoUrl) {
    try {
        mediaPlayer.reset();
        mediaPlayer.setDataSource(videoUrl);
                    mediaPlayer.setLooping(true);
        mediaPlayer.prepare();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public void pause() {
    mediaPlayer.pause();
}

public void stop() {
    if (mediaPlayer != null) {
        mediaPlayer.stop();
        mediaPlayer.release();
        mediaPlayer = null;
    }
}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    Log.e("mediaPlayer", "surface changed");
}

@Override
public void surfaceCreated(SurfaceHolder arg0) {
    try {
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setDisplay(surfaceHolder);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setOnBufferingUpdateListener(this);
        mediaPlayer.setOnPreparedListener(this);
    } catch (Exception e) {
        Log.e("mediaPlayer", "error", e);
    }
    Log.e("mediaPlayer", "surface created");
}

@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    Log.e("mediaPlayer", "surface destroyed");
}

@Override
public void onPrepared(MediaPlayer arg0) {
    videoWidth = mediaPlayer.getVideoWidth();
    videoHeight = mediaPlayer.getVideoHeight();
    if (videoHeight != 0 &amp;&amp; videoWidth != 0) {
        arg0.start();
    }
    Log.e("mediaPlayer", "onPrepared");
}

@Override
public void onCompletion(MediaPlayer arg0) {
    // TODO Auto-generated method stub
}

@Override
public void onBufferingUpdate(MediaPlayer arg0, int bufferingProgress) {
    skbProgress.setSecondaryProgress(bufferingProgress);
    int currentProgress = skbProgress.getMax()
            * mediaPlayer.getCurrentPosition() / mediaPlayer.getDuration();
    Log.e(currentProgress + "% play", bufferingProgress + "% buffer");
}
</code></pre>

<p>}</p>
