title: How to add MediaController to list of music with MediaPlayer?
body: <p>I'm new in android development. I want to create a music player with music from raw folder. I've created a ListView with list of music and set MediaPlayer. It works, music plays when click on item of ListView. Now I want to add MediaController to control playing this music (pause, play next and previous, etc). Read many tutorials on this topic including <a href="https://code.tutsplus.com/tutorials/create-a-music-player-on-android-project-setup--mobile-22764?ec_unit=translation-info-language" rel="nofollow noreferrer">https://code.tutsplus.com/tutorials/create-a-music-player-on-android-project-setup--mobile-22764?ec_unit=translation-info-language</a> .
  I wrote some code to add MediaController but it doesn't show on screen. There is no any error in Logcat.
  Here is <code>MainActivity</code></p>
  
  <pre><code>public class MainActivity extends Activity implements MediaController.MediaPlayerControl{
  
  ListView listSongs;
  ArrayList&lt;Song&gt; arrayList;
  ArrayAdapter&lt;Song&gt; mAdapter;
  MediaPlayer mPlayer;
  private MediaController controller;
  
  @Override
  protected void onCreate(Bundle saveInstanceState){
      super.onCreate(saveInstanceState);
      setContentView(R.layout.activity_music_category);
      listSongs = findViewById(R.id.list_songs);
      arrayList = new ArrayList&lt;&gt;();
      arrayList.add(new Song("Song1", R.raw.song1));
      arrayList.add(new Song("Song2", R.raw.song2));
      mAdapter = new ArrayAdapter&lt;&gt;(this, R.layout.text_view_forlist, arrayList);
      listSongs.setAdapter(mAdapter);
      mPlayer = new MediaPlayer();
      controller = new MediaController(this);
      controller.setMediaPlayer(this);
      listSongs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              if(mPlayer != null){
                  mPlayer.release(); 
              }
              mPlayer = MediaPlayer.create(MainActivity.this, arrayList.get(position).getmSongResourceId());
              mPlayer.start();
              controller.show(); 
          }
      });
  }
  
  @Override
  public void start() {
      mPlayer.start();
  }
  
  @Override
  public void pause() {
      mPlayer.pause();
  }
  
  @Override
  public int getDuration() {
      return mPlayer.getDuration();
  }
  
  @Override
  public int getCurrentPosition() {
      return mPlayer.getCurrentPosition();
  }
  
  @Override
  public void seekTo(int pos) {
      mPlayer.seekTo(pos);
  }
  
  @Override
  public boolean isPlaying() {
      return mPlayer.isPlaying();
  }
  
  @Override
  public int getBufferPercentage() {
      return 0;
  }
  
  @Override
  public boolean canPause() {
      return true;
  }
  
  @Override
  public boolean canSeekBackward() {
      return true;
  }
  
  @Override
  public boolean canSeekForward() {
      return true;
  }
  
  @Override
  public int getAudioSessionId() {
      return 0;
  }
  
  @Override
  protected void onStop() {
      super.onStop();
      controller.hide();
      mPlayer.stop();
      mPlayer.release();
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
      //the MediaController will hide after 3 seconds - tap the screen to make it appear again
      controller.show();
      return true;
  }
  }
  </code></pre>
  
  <p>and activity_music_category.xml:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  
  &lt;ListView
      android:id="@+id/list_songs"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:listSelector="@android:color/transparent"
      android:padding="0dp"
      android:paddingEnd="10dp"
      android:paddingStart="10dp" &gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p></p>
  
  <p>What should I do to display MediaController in the bottom when click on ListView item? I think maybe <code>controller.show();</code> is not in right place or I missed some methods or problem is more global. Thanks for any help.</p>