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

后端 未结 15 1072
独厮守ぢ
独厮守ぢ 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: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) {
            }
        }
    
    }
    

提交回复
热议问题