title: Android media player streaming
body: <p>i am working on android media player, which streams the video and displays. The application is able to buffer but the video is not being displayed on surface view though i am able to hear the sound.
  The following is my code:</p>
  
  <pre><code> public class VideoPlayerActivity extends Activity implements OnPreparedListener, OnCompletionListener, OnBufferingUpdateListener, OnSeekCompleteListener, OnErrorListener, SurfaceHolder.Callback {
  
       private VideoView videoView;
  
       private MediaPlayer mp;
  
       private SurfaceView surfaceView;
       private SurfaceHolder surfaceHolder;
  
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
  
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);
  
           //        getWindow().setFormat(PixelFormat.UNKNOWN);
  
           surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
  
           surfaceHolder = surfaceView.getHolder();
  
           surfaceHolder.addCallback(this);
  
           //        surfaceHolder.setFixedSize(176, 144);
           //        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
  
           try {
  
               String path = "http://xxxxxxxxxxx/4_xxx.mp4";
  
               mp = new MediaPlayer();
  
               mp.setDataSource(path);
               mp.setDisplay(surfaceHolder);
               mp.prepare();
  
               mp.setOnPreparedListener(this);
               mp.setOnBufferingUpdateListener(this);
               mp.setOnCompletionListener(this);
               mp.setOnSeekCompleteListener(this);
               mp.setOnErrorListener(this);
               mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
  
  
  
           } catch (IllegalArgumentException e) {
  
               e.printStackTrace();
  
           } catch (IllegalStateException e) {
  
               e.printStackTrace();
  
           } catch (IOException e) {
  
               e.printStackTrace();
  
           }
  
           mp.start();
  
           //        Uri uri = Uri.parse(path);
           //        
           //        videoView = (VideoView) findViewById(R.id.videoView1);
           //        
           //        videoView.setVideoURI(uri);
           //        
           //        videoView.setMediaController(new MediaController(this));
           //        
           //        
           //        
           //        videoView.setOnPreparedListener(this);
           //        
           //        
           //        
           //        videoView.requestFocus();
           //        
           //        videoView.start();
       }
  
       @Override
       public void onPrepared(MediaPlayer mp) {
  
           System.out.println("=======In on prepared======Media Player=====" + mp);
  
       }
  
       @Override
       public void onCompletion(MediaPlayer mp) {
  
           System.out.println("=======In on completion====== Media player====" + mp);
  
       }
  
       @Override
       public void onBufferingUpdate(MediaPlayer mp, int percent) {
  
           System.out.println("=======In on Buffering update======Media Player====" + mp + "====percent====" + percent);
  
       }
  
       @Override
       public boolean onError(MediaPlayer mp, int what, int extra) {
  
  
           System.out.println("=======In on Error======Media Player====" + mp + "=====what====" + what + "====extra====" + extra);
  
           return false;
       }
  
       @Override
       public void onSeekComplete(MediaPlayer mp) {
  
           System.out.println("=======In on seek complete======Media Player====" + mp);
  
       }
  
       @Override
       public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
           // TODO Auto-generated method stub
  
       }
  
       @Override
       public void surfaceCreated(SurfaceHolder holder) {
           // TODO Auto-generated method stub
  
       }
  
       @Override
       public void surfaceDestroyed(SurfaceHolder holder) {
           // TODO Auto-generated method stub
  
       }
   }
  </code></pre>