Video Streaming with the Buffering happening in the Background in Android
===

I have been working on video playback of progressive videos from my android application. I am able to stream videos from internet.

But the video starts after buffering the whole data.

Here is the code I am using-

    protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
	    setContentView(R.layout.mediaplayer_2);
	    mPreview = (SurfaceView) findViewById(R.id.surface);
	    holder = mPreview.getHolder();
	    holder.addCallback(this);
	    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	    extras = getIntent().getExtras();
	}
	
	 private boolean playVideo(String movieUrl) {
	        doCleanUp();
	        try {
	        	path=movieUrl;

	           
	            // Create a new media player and set the listeners
	            mMediaPlayer = new MediaPlayer();
	            mMediaPlayer.setDataSource(path);
	            mMediaPlayer.setDisplay(holder);
	            mMediaPlayer.prepare();
	            mMediaPlayer.setOnBufferingUpdateListener(this);
	            mMediaPlayer.setOnCompletionListener(this);
	            mMediaPlayer.setOnPreparedListener(this);
	            mMediaPlayer.setOnVideoSizeChangedListener(this);
	            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
	            return true;


	        } catch (Exception e) {
	            Log.e(TAG, "error: " + e.getMessage(), e);
	            return false;
	        }
	    }
	 
	   public void onBufferingUpdate(MediaPlayer arg0, int percent) {
	        Log.d(TAG, "onBufferingUpdate percent:" + percent);

	    }

	    public void onCompletion(MediaPlayer arg0) {
	        Log.d(TAG, "onCompletion called");
	    }

	 
	  private void doCleanUp() {
	        mVideoWidth = 0;
	        mVideoHeight = 0;
	        mIsVideoReadyToBePlayed = false;
	        mIsVideoSizeKnown = false;
	    }
	  
	  public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
	        Log.v(TAG, "onVideoSizeChanged called");
	        if (width == 0 || height == 0) {
	            Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
	            return;
	        }
	        mIsVideoSizeKnown = true;
	        mVideoWidth = width;
	        mVideoHeight = height;
	        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
	            startVideoPlayback();
	        }
	    }

	    public void onPrepared(MediaPlayer mediaplayer) {
	        Log.d(TAG, "onPrepared called");
	        mIsVideoReadyToBePlayed = true;
	        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
	            startVideoPlayback();
	        }
	    }

	    public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
	        Log.d(TAG, "surfaceChanged called");

	    }

	    public void surfaceDestroyed(SurfaceHolder surfaceholder) {
	        Log.d(TAG, "surfaceDestroyed called");
	    }


	    public void surfaceCreated(SurfaceHolder holder) {
	        Log.d(TAG, "surfaceCreated called");
	        vidAppTask=new VideoAppTask();
	        vidAppTask.execute();
	        


	    }

	    @Override
	    protected void onPause() {
	        super.onPause();
	        releaseMediaPlayer();
	        doCleanUp();
	    }

	    @Override
	    protected void onDestroy() {
	        super.onDestroy();
	        releaseMediaPlayer();
	        doCleanUp();
	    }

	    private void releaseMediaPlayer() {
	        if (mMediaPlayer != null) {
	            mMediaPlayer.release();
	            mMediaPlayer = null;
	        }
	    }
	    
	    private void startVideoPlayback() {
	        Log.v(TAG, "startVideoPlayback");
	        holder.setFixedSize(mVideoWidth, mVideoHeight);
	        mMediaPlayer.start();
	    }

This code is working fine, but not playing before the whole video gets buffered.

Is there anyway we can stream the video while buffering it in the background.

Thanks.