Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thomas, I'll try to explain the <a href="https://stackoverflow.com/questions/3747139/how-can-i-show-a-mediacontroller-while-playing-audio-in-android/5265629#5265629">link</a> here.</p> <p>First, you need to define your player, controller, and handler fields:</p> <pre><code> private MediaPlayer mediaPlayer; private MediaController mediaController; private Handler handler = new Handler(); </code></pre> <p>Next, you need to instantiate all of your appropriate objects (as you have done), as well as register an OnPreparedListener:</p> <pre><code>mediaPlayer = new MediaPlayer(); mediaPlayer.setOnPreparedListener(this); mediaController = new MediaController(this); </code></pre> <p>Then, you prepare and start the mediaPlayer:</p> <pre><code>try { mediaPlayer.setDataSource(audioFile); mediaPlayer.prepare(); mediaPlayer.start(); } catch (IOException e) { Log.e(TAG, "Could not open file " + audioFile + " for playback.", e); } </code></pre> <p>When the mediaPlayer is prepared, the controller will be set:</p> <pre><code> public void onPrepared(MediaPlayer mediaPlayer) { Log.d(TAG, "onPrepared"); mediaController.setMediaPlayer(this); handler.post(new Runnable() { public void run() { mediaController.setEnabled(true); mediaController.show(); } }); } </code></pre> <p>Does it make more sense now?</p> <p>EDIT: This is how you would play a file from the res/raw folder:</p> <pre><code>int resID=getResources().getIdentifier("filename", "raw", getPackageName()); MediaPlayer mediaPlayer=MediaPlayer.create(this,resID); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload