Android MediaPlayer full path to file

前端 未结 3 1682
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 22:23

I need to get the full path to a file somewhere on the phone (any location) and play it with MediaPlayer.

ive heard of using a file chooser for Android (by launching an

3条回答
  •  囚心锁ツ
    2021-02-04 22:44

    Some points:

    1. Do not call prepare() twice (once in the constructor and the other explicitly). That could be one of the reasons that the IllegalStateException is thrown.
    2. Also, is the file that you are trying to play inside the application? If so, why are you trying to create a stream? If the file is already within the application (and within /res/raw, you could try and save yourself the hassle of using prepare() by creating the mediaplayer object like so:

      mediaplayer = new MediaPlayer.create(this, R.raw.resource-name here);

    The create function calls prepare() within.
    3. You can also try and use the reset() function if any one of the stages in the MediaPlayer fails resulting in the MediaPlayer object entering the error state. Using reset() would bring it back to Idle state.
    4. The last time I had that error status=0x1 message, it turned out that I had not had the correct permissions set for the files (external storage etc. in Manifest) and some files placed in incorrect folders. You may also want to take a look at that.

    Let me know in case that does not work,
    We can try something else.
    Sriram.

提交回复
热议问题