Android MediaPlayer throwing “Prepare failed.: status=0x1” on 2.1, works on 2.2

后端 未结 15 967
独厮守ぢ
独厮守ぢ 2020-11-27 17:17

I\'ve been really banging my head against the table trying to get the MediaPlayer class to try to play h.264-encoded videos on Android 2.1. My code is rather simple:

<
相关标签:
15条回答
  • 2020-11-27 17:54

    If you are dealing with remote URL, use below code to get encoded url compatible with MediaPlayer.

    public String getEncodedURL(String urlStr) throws Exception 
    {
                URL url = new URL(urlStr);
                URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
                urlStr = uri.toASCIIString();
                return urlStr;
    }
    
    0 讨论(0)
  • 2020-11-27 17:56

    I had a similar problem. I had a zip file which contained sound files which were compressed. In order to pass them on to MediaPlayer they needed to be uncompressed. When I placed them inside application's cache directory (context.getCacheDir()), MediaPlayer returned the same error which you described.

    But when I placed them on external storage (Environment.getExternalStorageDirectory()), everything started working.

    0 讨论(0)
  • 2020-11-27 17:57

    This is my solution:

    MediaPlayer mediaPlayer = new MediaPlayer();
    FileInputStream fis = null;
    try {
        File directory = new File("android.resource://com.example.myapp/raw/");
        fis = new FileInputStream(directory);
        mediaPlayer.setDataSource(fis.getFD());
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.prepare();
    }   finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException ignore) {
            }
        }
    
    }
    
    0 讨论(0)
  • 2020-11-27 17:57

    playing mp3 files instead of wmva fixed it. Apparently that isn't an issue on API 19

    0 讨论(0)
  • 2020-11-27 17:59

    On my opinion i will ask you to check back your location of your media files<< SONG PATH or MOVIE PATH >>. I faced with this exception, i have overcome by correct "SONG PATH"

    0 讨论(0)
  • 2020-11-27 18:00

    In my case it was just a filename that it didn't like:
    /storage/emulated/0/appname/2018-03-12T11:52:08Z.wav
    Removed the hyphens and colons, and the exception went away.

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