java - Error: mediaplayer start called in state 0 error(-38,0) -
I'm new to Android and I have Meediapayr link to play music on which is written the code
i boolean flag; @Override protect a folder path = "// localhost / Android / SD / vande.mp3
public class MainActivity extends Activity {button to start, stop, made stop file contains zero onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); start = (button) findViewById (R.id.button1); pause = (button) findViewById (R.id.button2); stop = (button) findViewById (R.id.button3); final MediaPlayer mp = new MediaPlayer (); try {mp.setDataSource (Environment.getExternalStorageDirectory () getPath () + '/ Android / music / vande.mp3 ".) ; mp.prepare ();} catch (Exception e) {e.printStackTrace ();} mp.setOnPreparedListener (New MediaPlayer.OnPreparedListener () {public void onPrepared (MediaPlayer player) {//mp.start (); flag = true ;}}); If (flag == true) {override public zeros at {start.setOnClickListener (New OnClickListener () {@ click (see V) {mp.start ();}}); } Other {stop.setOnClickListener (New OnClickListener () {@Override Click Public Zero (see V) {mp.stop ();}}); } pause.setOnClickListener (New OnClickListener () {@Override Click Public Zero (see V) {mp.pause ();}}); }} But when I check the logk, the file is not running, an error pops up "Start calling in 0 error (-38,0)"
can
help you solve this code
mp.setOnPreparedListener (new MediaPlayer.OnPreparedListener () {;} public void onPrepared (MediaPlayer player) {mp.start ()}) calls If you start the player by clicking the button> Received want, you can have a flag. Boolean flag = false; then > <(> flag == true) {Former> Provider on public void (mediaplayer player) {flag = true;}
mp.start ();} Other {// media player not ready}
Comments
Post a Comment