Media Player called in state 0, error (-38,0)

mediaplayer start called in state 1 error (-38 0)
prepareasync called in state 8
mediaplayer android
mediaplayer reset
mediaplayer seekto
mediaplayer stop
mediaplayer setsurface
mediaplayer prepare

I am currently trying to design a simple app that streams an internet radio station. I have the URL for the station and am setting up the Media Player like

    MediaPlayer mediaPlayer = new MediaPlayer();
    try {
        mediaPlayer.setDataSource(URL);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        mediaPlayer.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    mediaPlayer.start();

The program isn't crashing when emulated, but nothing is playing and I am get the following error:

start called in state 0

and right below it is

Error (-38,0)

Does anyone know what this means?

I've read a little about these state errors, but couldn't find anything that applies to my project.

You need to call mediaPlayer.start() in the onPrepared method by using a listener. You are getting this error because you are calling mediaPlayer.start() before it has reached the prepared state.

Here is how you can do it :

mp.setDataSource(url); 
mp.setOnPreparedListener(this);
mp.prepareAsync();

public void onPrepared(MediaPlayer player) {
    player.start();
}

Media Player called in state 0, error (-38,0), E/MediaPlayer: start called in state 0 E/MediaPlayer: error (-38, 0) mattapperson changed the title start called in state 0 [Android] start called  Xamarin.Forms MediaElement. 02/18/2020; 16 minutes to read; In this article. Download the sample. MediaElement is a view for playing video and audio. Media that's supported by the underlying platform can be played from the following sources: The web, using a URI (HTTP or HTTPS). A resource embedded in the platform application, using the ms-appx

It seems like Error -38 means a state-exception (as the error-message indicates). For example if you call start(), before the song was ready, or when you call pause(), even if the song isn't playing at all.

To fix this issue check the state of the mediaPlayer before calling the methods. For example:

if(mediaPlayer.isPlaying()) {
    mediaPlayer.pause();
}

Additionally, the MediaPlayer is sending event-messages. Even if you do not need the prepared-event (although it would be a good idea to not start the playback before this event was fired) you must set a callback-listener. This also holds true for the OnErrorListener, OnCompletionListener, OnPreparedListener and OnSeekCompletedListener (if you call the seek method).

Listeners can be attached simply by

mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        // Do something. For example: playButton.setEnabled(true);
    }
});

[Android] start called in state 0 · Issue #261 · react-native-community , MediaPlayer in PREPARED state when calling pause after setting the speed .​com/questions/15589845/android-media-player-pause-called-in-state-8 14743​-14931/com.example.player E/MediaPlayer: Error (-38,0)  Windows Media Player includes some of the most popular codecs, like MP3, Windows Media Audio, and Windows Media Video. However, it doesn't include the codecs required for Blu‑ray Disc files, FLAC files, or FLV files. If something isn’t working in Windows Media Player, you might not have the right codec on your PC.

I got this error when I was trying to get the current position (MediaPlayer.getCurrentPosition()) of media player when it wasn't in the prepared stated. I got around this by Keeping track of its state and only calling the getCurrentPosition() method after onPreparedListener is called.

MediaPlayer in PREPARED state when calling pause after setting , Android MediaPlayer Problems :“Error (-38 , 0) ” and “stop called in state 1”. It's no sound from my device even the emulator. Actually, at the line  AVPlayer is a dynamic object whose state continuously changes. There are two approaches you can use to observe a player’s state: General State Observations: You can use Key-value observing (KVO) to observe state changes to many of the player’s dynamic properties, such as its current Item or its playback rate. You should register and

This is my code,tested and working fine:

package com.example.com.mak.mediaplayer;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.app.Activity;

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final MediaPlayer mpp = MediaPlayer.create(this, R.raw.red); //mp3 file in res/raw folder

    Button btnplay = (Button) findViewById(R.id.btnplay); //Play
    btnplay.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View vone) {
        mpp.start();
      }
    });

    Button btnpause = (Button) findViewById(R.id.btnpause); //Pause
    btnpause.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View vtwo) {
        if (mpp.isPlaying()) {
          mpp.pause();
          mpp.seekTo(0);
        }
      }
    });
  }
}

Android MediaPlayer Problems :“Error (-38 , 0) ” and “stop called in , Media.stop() puts media into an unplayable state. Status: mCurrentState=64 08​-20 12:20:32.381: E/MediaPlayer(13077): error (-38, 0) 08-20 08-20 12:20:​32.381: E/MediaPlayer(13077): pause called in state 0 08-20  A value of 0.0 should not be set by the client. If it is, the media player should act as though Pause was called. If the media player has no ability to play at speeds other than the normal playback rate, this must still be implemented, and must return 1.0.

i tested below code. working fine

public class test extends Activity implements OnErrorListener, OnPreparedListener {

private MediaPlayer player;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    player = new MediaPlayer();
    player.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {
        player.setDataSource("http://www.hubharp.com/web_sound/BachGavotte.mp3");
        player.setOnErrorListener(this);
        player.setOnPreparedListener(this);
        player.prepareAsync();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }       
}
@Override
public void onDestroy() {
    super.onDestroy();
    player.release();
    player = null;
}
@Override
public void onPrepared(MediaPlayer play) {
    play.start();
}
@Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
    return false;
}
}

[#CB-1264] Media.stop() puts media into an unplayable state., If any of these methods is called right after a MediaPlayer object is constructed, by the internal player engine and the object will be transfered to the Error state. The valid range of the index is 0..total number of tracks - 1. Gets or sets the volume for the player. The setter accepts a float between 0 and 1. muted Gets or sets the muted state of the player. The setter accepts a boolean. hasAudio -Returns a boolean indicating if the current media has an audio track. speed Gets or sets the speed for the player.

MediaPlayer, Ask questionsAndroid not working with error (-38, 0). iOS can working https://​stackoverflow.com/questions/9008770/media-player-called-in-state-0-error-38-0. A media server must have a hard drive or memory card where the media is saved. The saved media can be called up by a digital media player. The media server makes the files available to stream media to the player.

Android not working with error (-38, 0) - audioplayers, I have used MediaPlayer to play music for my game on multiple phones, even some very 01-12 12:02:51.477 E/MediaPlayerNative(14701): stop called in state 0, error (-38, 0) 01-12 12:02:51.492 V/MediaPlayer(14701):  A player is not prepared to respond to commands quasi-immediately until its status has transitioned to MediaPlayer.Status.READY, which in effect generally occurs when media pre-roll completes. Some requests made of a player prior to its status being READY will however take effect when that status is entered.

MediaPlayer not working on a tablet. E/MediaPlayerNative: error (1 , cordova-plugin-media. This plugin provides the ability to record and play back audio files on a device. NOTE: The current implementation does not adhere to a W3C specification for media capture, and is provided for convenience only. A future implementation will adhere to the latest W3C specification and may deprecate the current APIs.

Comments
  • stackoverflow.com/questions/8681550/… stackoverflow.com/questions/8671479/…
  • possible duplicate of Android MediaPlayer Problems :"Error (-38 , 0) " and "stop called in state 1"
  • @SmashCode please mark another answer as the accepted as my answer is totaly useless.
  • This solution works just replace mp.start(); with player.start();
  • What if we don't want it to start right away? Even if I initialize my player and wait a minute or so, the first time i try to play it, it has this error unless I call .start() in onPrepared
  • You prepare it before and remember you prepared it. In parallel, you try to remember if you want to run it. When it is both prepared and you want to run it, you start it.
  • calling pause() on not playing player was my case
  • calling mediaPlayer.isPlaying() in an invalid state will send the media player into an error state. Better to maintain an explicit enum to maintain states.
  • How did you figure out it was for that reason?
  • For and update to SetAudioStreamType(..) use SetAudioAttributes(...)
  • I can't ask an internet radio station to change their file format.
  • Do you get the "Can't play this video" popup? How do you deal with it? I catch the error but get this modal regardless and I have no control over the source of media as it comes from a public API. If anyone knows how to prevent the "Can't play this video" modal I would be grateful.
  • Did you try setting an error listener. MediaPlayer mp = new MediaPlayer() { @Override public void setOnErrorListener(android.media.MediaPlayer.OnErrorListener listener) { // Do stuff here.. } }; mp.setDataSource(..
  • Could you be more specific?
  • Sorry,English is not my first language,and I'm also not good at it...but I just want to help others that have the same questions,that's all.