mediaPlayer error -38,0

后端 未结 5 1759
梦如初夏
梦如初夏 2020-12-01 07:18

I try to do simple online radio player. Here is adress of stream http://radio-electron.ru:8000/96 Here is my code.

MyActivity.java

package com.exampl         


        
相关标签:
5条回答
  • 2020-12-01 07:28

    I was getting my -38 error by calling getDuration(); on the MediaPlayer before it was prepared.


    It's worth checking the MediaPlayer doc.

    There is a paragraph that starts It is a programming error to invoke methods such as getCurrentPosition()...

    that has a list of methods which are un-ideal to call before the MediaPlayer is prepared, which in turn may result in -38.

    0 讨论(0)
  • 2020-12-01 07:35

    @allprog and @Michael are right. But there is another way, if you don't want to use prepareAsync(), use prepare(). That is blocking, which is returned only when it is prepared.

    0 讨论(0)
  • 2020-12-01 07:45

    The error code -38 ought to correspond to INVALID_OPERATION.

    A likely cause of this is that you don't wait for prepareAsync to finish before you call start. You should set an onPreparedListener and start the MediaPlayer only when onPrepared has been called.

    0 讨论(0)
  • 2020-12-01 07:48

    -38 refers to ENOSYS error code from errno.h (see this explanation https://stackoverflow.com/a/15206308/768935)

    You seem to try to start the playing before the preparation is complete. Use the setOnPreparedListener() method to set a preparation listener and call the start() method only after the preparation is complete.

    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
      public void onPrepared(MediaPlayer mp) {
          mp.start();
      }
    });
    mediaPlayer.prepareAsync();
    

    And remove the current mediaPlayer.start() invocation from the code.

    0 讨论(0)
  • 2020-12-01 07:50

    You better check if you are executing any operation that is related to the playing state like getCurrentPosition() before the Mediaplayer is started.

    0 讨论(0)
提交回复
热议问题