Question

I got error code with 1,-4 number in android media player

I use this code for playing music in my service

   public void playNextSong(/* String manualUrl */) {
    mState = State.Stopped;
    relaxResources(true); // release everything except MediaPlayer

    AudioFile file = playList.nextFile();
    if (file == null) {
        say("Tidak ada lagu di playlist");
        return;
    }

    try {
        // set the source of the media player a a content URI
        createMediaPlayerIfNeeded();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.setDataSource(getApplicationContext(), file.getUri());

        mState = State.Preparing;
        // MUST call this!
        setUpAsForeground(file.getTitle() + " (loading)");

        // starts preparing the media player in the background. When it's
        // done, it will call
        // our OnPreparedListener (that is, the onPrepared() method on this
        // class, since we set
        // the listener to 'this').
        //
        // Until the media player is prepared, we *cannot* call start() on
        // it!
        mPlayer.prepareAsync();

    } catch (IOException ex) {
        Log.e("MusicService",
                "IOException playing next song: " + ex.getMessage());
        ex.printStackTrace();
    }
    }

And I use this in the shake listener of my code

  mSensorListener
            .setOnShakeListener(new ShakeEventListener.OnShakeListener() {

                public void onShake() {
                    musicService.playNextSong();
                    updateInformation(musicService.playList.getCurrent());
                }
            });

Anyone can help to handle player not in invalid states exceptions

Was it helpful?

Solution

Check this link. It has a description of error codes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top