title: android media player stops playing after some minutes
body: <p>I have an issue with Media player always stopping randomly after some few mins, most times, when the phone sleeps and you touch it again, the video hangs and stops playing.</p>
  
  <p>I have tried many solutions here on stackoverflow, none worked. I'm almost pulling my hair out !!!</p>
  
  <p>I've tried this answer</p>
  
  <p><a href="https://stackoverflow.com/questions/19566450/android-mediaplayer-stops-playing-after-some-time">Android MediaPlayer stops playing after some time</a></p>
  
  <p><a href="https://stackoverflow.com/questions/19918118/mediaplayer-randomly-stops-on-android-4-4-19">MediaPlayer randomly stops on Android 4.4 (19)</a></p>
  
  <p><a href="https://stackoverflow.com/questions/13096715/how-to-prevent-mediaplayer-to-stop-when-screen-goes-off">How to prevent mediaplayer to stop when screen goes off?</a>  </p>
  
  <p>and many more answers, they all didn't work</p>
  
  <p>This is my code below</p>
  
  <pre><code>public class MainActivity {
  
      MediaPlayer mp;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);
  
          mp = MediaPlayer.create(this, R.raw.my_webm_video);
  mp.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
          playVideo();
  
      }
  
      @Override
      public void onResume() {
          super.onResume();
          mp = MediaPlayer.create(this, R.raw.my_webm_video);
          mp.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
          playVideo();
      }
  
      public void playVideo(){
  
          SurfaceView sv = (SurfaceView) findViewById(R.id.surfaceView);
          SurfaceHolder holder = sv.getHolder();
          holder.addCallback(new SurfaceHolder.Callback(){
              @Override
              public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { }
  
              @Override
              public void surfaceCreated(SurfaceHolder holder) {
                 mp.setDisplay(holder);
                 mp.start();
                 mp.setLooping(true);
              }
  
              @Override
              public void surfaceDestroyed(SurfaceHolder holder) {
  
              }
  
          });
      }
  
  
  }
  </code></pre>
  
  <p>This is my XML layout </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"&gt;
  
      &lt;SurfaceView
          android:id="@+id/surfaceView"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>