title: Android Media Controller hides when loses focus
body: <p>I'm using a media controller associated with a media player to play a sound. The issue is that the media controller is hiding as soon as it loses focus. I have a button which when pressed, the sound is played and the media controller shows up at the bottom of the screen. </p>
  
  <p>But when life pause is pressed, after like 5 seconds, the media controller itself hides.</p>
  
  <p>here are part of my codes. I'm stopping the media player as soon as the media controller hides so that the sound is not continually played</p>
  
  <p>All the codes for the media controller are:</p>
  
  <pre><code>     mediaPlayer = new MediaPlayer();
                              mediaPlayer.setOnPreparedListener(currentFragment);
  
                              mediaController = new MediaController(getActivity()){
                                  @Override
                                  public void hide()
                                  {
  
                                      if(mediaPlayer.isPlaying()){
                                          mediaPlayer.stop(); 
                                      }
                                      super.hide();
                                  }
                              };
  
  
                                try {
                                  mediaPlayer.setDataSource(sound.getSound());
                                   mediaPlayer.prepareAsync();
                              } catch (IllegalArgumentException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                              } catch (SecurityException 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();
  
  
      @Override
              public void onPrepared(MediaPlayer mp) {
                  Log.d("media status", "onPrepared");
  
  
  
                  handler.post(new Runnable() {
                    public void run() {
  
                        launchMediaController();
                        progress.dismiss();
                    }
                  });
  
              }
  
  
  
  void launchMediaController(){
              mediaController.setEnabled(true);
  
              mediaPlayer.start();
              mediaController.setMediaPlayer(soundController);
              mediaController.setAnchorView(getView());
              mediaController.show(0);
          }
  
          private class SoundController implements MediaController.MediaPlayerControl{
  
              public void start() {
                  mediaPlayer.start();
                }
  
                public void pause() {
                  mediaPlayer.pause();
                }
  
                public int getDuration() {
                  return mediaPlayer.getDuration();
                }
  
                public int getCurrentPosition() {
                  return mediaPlayer.getCurrentPosition();
                }
  
                public void seekTo(int i) {
                  mediaPlayer.seekTo(i);
                }
  
                public boolean isPlaying() {
                  return mediaPlayer.isPlaying();
                }
  
                public int getBufferPercentage() {
                  return 0;
                }
  
                public boolean canPause() {
                  return true;
                }
  
                public boolean canSeekBackward() {
                  return true;
                }
  
                public boolean canSeekForward() {
                  return true;
                }
  
              @Override
              public int getAudioSessionId() {
                  // TODO Auto-generated method stub
                  return 0;
              }   
        }
  </code></pre>
  
  <p><strong>Edits:</strong>
  Based on the answer of Libin, I did the following with no success:
  <strong>Extends MediaController and overrides touch event</strong></p>
  
  <pre><code>private class MyMediaController extends MediaController{
  
              public MyMediaController(Context context) {
                  super(context);
                  // TODO Auto-generated constructor stub
              }
              @Override
              public boolean onTouchEvent(MotionEvent event) {
                  return true;
              }
          }
  </code></pre>
  
  <p><strong>Use extended class</strong> </p>
  
  <pre><code>mediaController = new MyMediaController(getActivity()){
                              @Override
                              public void hide()
                              {
  
                                  if(mediaPlayer.isPlaying()){
                                      mediaPlayer.stop(); 
                                  }
                                  super.hide();
                              }
                          };
  </code></pre>
  
  <p>launchMediaController() is actually what launches the media controller.
  My question, why does the media controller hides by itself after some seconds after the user touches it? Is there any solution to this?</p>