I want to play 2 videos one after one minimizing delay between each video.
so I created 2 mediaplayer, one playing the current video and the other preparing to play the following video.
the 1st video is played correctely but I couldn't get the video track of the second video. only sound without any error. can somebody help?
thanks.
this is my source code :
(note that here, I am using files on sdcard but the application will use files on a web server. that's why I need to prepare the second video while the 1st is playing)
Using java Syntax Highlighting
- package com.test.testvideo;
- import android.app.Activity;
- import android.os.Bundle;
- import android.media.MediaPlayer;
- import android.view.SurfaceView;
- import android.util.Log;
- import android.view.SurfaceHolder;
- import android.media.AudioManager;
- import android.widget.Button;
- public class Test extends Activity implements
- MediaPlayer.OnPreparedListener, SurfaceHolder.Callback,
- MediaPlayer.OnCompletionListener {
- SurfaceView sf = null;
- int currplayer = 0;
- MediaPlayer mp1 = null;
- MediaPlayer mp0 = null;
- int currvideo = 0;
- SurfaceHolder holder = null;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- this.sf = (SurfaceView)findViewById(R.id.sf);
- this.holder = sf.getHolder();
- holder.addCallback(this);
- holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- }
- public void onPrepared(MediaPlayer mp){
- Log.v("onPrepared()", "prepared...");
- if(currplayer == 0) {
- currvideo++;
- String nexturl = "/sdcard/"+currvideo+".3gp";
- try {
- mp1.setDataSource(nexturl);
- }
- catch(Exception e){
- }
- mp1.setDisplay(holder);
- mp1.prepareAsync();
- mp1.setOnPreparedListener(this);
- mp1.setOnCompletionListener(this);
- mp1.setAudioStreamType(AudioManager.STREAM_MUSIC);
- currplayer=1;
- }
- }
- public void onCompletion(MediaPlayer mp) {
- Log.v("onCompletion()"+currplayer, "completed...");
- if(currplayer == 1) {
- mp0.stop();
- mp0.release();
- mp1.start();
- currplayer = 0;
- }
- }
- public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
- Log.d("surfaceChanged()", "surfaceChanged...");
- }
- public void surfaceDestroyed(SurfaceHolder surfaceholder) {
- Log.d("surfaceDestroyed()", "surfaceDestroyed...");
- }
- public void surfaceCreated(SurfaceHolder holder) {
- Log.d("surfaceCreated()", "surfaceCreated...");
- mp0 = new MediaPlayer();
- mp1 = new MediaPlayer();
- try {
- mp0.setDataSource("/sdcard/0.3gp");
- mp0.setDisplay(holder);
- mp0.prepare();
- }
- catch(Exception e){
- }
- mp0.setOnPreparedListener(this);
- mp0.setOnCompletionListener(this);
- mp0.start();
- mp0.setAudioStreamType(AudioManager.STREAM_MUSIC);
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (mp0 != null) {
- mp0.release();
- mp0 = null;
- }
- if (mp1 != null) {
- mp1.release();
- mp1 = null;
- }
- }
- }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


