Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From the <a href="http://developer.android.com/reference/android/media/MediaPlayer.html" rel="nofollow noreferrer"><code>MediaPlayer</code> API docs</a>:</p> <blockquote> <p>When a <code>MediaPlayer</code> object is just created using new or after <code>reset()</code> is called, it is in the <em>Idle</em> state; and after <code>release()</code> is called, it is in the <em>End</em> state. Between these two states is the life cycle of the <code>MediaPlayer</code> object.</p> <p>It is a <strong>programming error</strong> to invoke methods such as <code>getCurrentPosition()</code>, <code>...</code> , <code>setAudioStreamType(int)</code> in the Idle state.</p> </blockquote> <p>You should study the <code>MediaPlayer</code> lifecycle diagram and provided examples and rewrite your code with respect to them. In this case, you see you need to call <code>setDataSource()</code> <strong><em>before</em></strong> <code>setAudioStreamType()</code>.</p> <p><img src="https://developer.android.com/images/mediaplayer_state_diagram.gif" alt="alt text"></p> <hr> <p><strong>Side note</strong>: In Android, you really need to follow the lifecycle events for everything you do, or you'll get bitten. You can write incorrect code and you'll never know until runtime, or worse you might write code you think works and you'll only discover in weird circumstances that it doesn't... e.g. the screen orientation changes and the callback method is not the same in this case, or other similar situations (Home button...etc).</p>
 

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