title: Playing a Video In Android App
body: <p><strong>EDIT------------</strong>
  <em>I want to have multiple videos and when you slide your finger across the screen it goes to the next video with the pause and play buttons.</em></p>
  
  <p>LINK TO MY FILES: <a href="http://www.mediafire.com/?ap12kiibfe438bf" rel="nofollow">http://www.mediafire.com/?ap12kiibfe438bf</a></p>
  
  <p><strong>----------------</strong></p>
  
  <p>Im making this app that plays videos and it simple exept i have multipul videos to play and im not sure if all my coding is right and im not sure how to implement scrolling from one video to the next. </p>
  
  <p>This is my Java Code:</p>
  
  <pre><code>    package com.exercise.AndroidVideoPlayer;
  
  import java.io.IOException;
  
  import android.app.Activity;
  import android.graphics.PixelFormat;
  import android.media.AudioManager;
  import android.media.MediaPlayer;
  import android.os.Bundle;
  import android.view.SurfaceHolder;
  import android.view.SurfaceView;
  import android.view.View;
  import android.widget.Button;
  
  public class AndroidAudioPlayer extends Activity implements SurfaceHolder.Callback{
  
      MediaPlayer mediaPlayer;
      SurfaceView surfaceView;
      SurfaceHolder surfaceHolder;
      boolean pausing = false;;
  
      String stringPath = "/sdcard/samplevideo.3gp";
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          Button buttonPlayVideo = (Button)findViewById(R.id.playvideoplayer);
          Button buttonPauseVideo = (Button)findViewById(R.id.pausevideoplayer);
  
          getWindow().setFormat(PixelFormat.UNKNOWN);
          surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
          surfaceHolder = surfaceView.getHolder();
          surfaceHolder.addCallback(this);
          surfaceHolder.setFixedSize(176, 144);
          surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
          mediaPlayer = new MediaPlayer();
  
          buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  pausing = false;
  
                  if(mediaPlayer.isPlaying()){
                      mediaPlayer.reset();
                  }
  
                  mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                  mediaPlayer.setDisplay(surfaceHolder);
  
                  try {
                      mediaPlayer.setDataSource(stringPath);
                      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();
                  }
  
                  mediaPlayer.start();
  
  
              }});
  
          buttonPauseVideo.setOnClickListener(new Button.OnClickListener(){
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  if(pausing){
                      pausing = false;
                      mediaPlayer.start();
                  }
                  else{   
                      pausing = true;
                      mediaPlayer.pause();
                  }
              }});
  
      }
  
  
  
      @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>
  
  <p>My main.xml:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
      &lt;ScrollView&gt; android:id="@+id/ScrollView01"
      android:layout_width="fill_parent"
      android:layout_height="110px"
  &lt;TextView  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/hello"
      /&gt;
  &lt;Button
      android:id="@+id/playvideoplayer"  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="- PLAY Video -"
      /&gt;
  &lt;Button
      android:id="@+id/pausevideoplayer"  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="- PAUSE Video -"
      /&gt;
  &lt;SurfaceView
      android:id="@+id/surfaceview"  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /&gt;
      &lt;TextView  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/hello"
      /&gt;
  &lt;Button
      android:id="@+id/playvideoplayer"  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="- PLAY Video -"
      /&gt;
  &lt;Button
      android:id="@+id/pausevideoplayer"  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="- PAUSE Video -"
      /&gt;
  &lt;SurfaceView
      android:id="@+id/surfaceview"  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /&gt;
      &lt;/ScrollView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>if you could please help me on how to scroll from one video to the next, like  do I just copy all the code and put it under what i did before? Or What?</p>
  
  <p>Sorry, if im not super helpful but I really need this done.</p>
  
  <p>Thanks</p>
  
  <p>Eric V</p>