ramzi shadid
ramzi shadid

Reputation: 81

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

i'm trying to use this code which i called from a button but it doesn't work and when i see the LogCat window i found Media Player called in state 0, error (-38,0)

public void audioPlayer(String path, String fileName){

//set up MediaPlayer    
        MediaPlayer mp = new MediaPlayer();

        try {
            mp.setDataSource(HeyActivity.this, Uri.parse(path+"/"+fileName));
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            mp.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            System.out.print("hey");
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        mp.start();

    }

Upvotes: 2

Views: 4542

Answers (2)

Sanjit Suchak
Sanjit Suchak

Reputation: 31

I finally solved the problem by running on an emulator that supported audio!!

Can't believe it was that simple!

Window > AVD Manager > Edit your AVD (I created a new one to be on the safe side cause I was running from snapshot) > Hardware > New > Audio Playback Support

Upvotes: 1

DDas
DDas

Reputation: 306

Try setting OnPreparedListener and call the start method within it. Like this:

MediaPlayer mp = new MediaPlayer();
mp.setOnPreparedListener( new OnPreparedListener() {

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

Upvotes: 2

Related Questions