Code example for MediaPlayer

Methods: preparereleasesetDataSourcesetVolume

0
        mp.release();
    } 
 
    public void close() { 
        if (null != androidPlayer) {
            androidPlayer.release();
            androidPlayer = null;
        } 
    } 
    public void play(String source, int volume) throws IOException {
        AudioManager audioManager = (AudioManager)JimmActivity.getInstance().getSystemService(Context.AUDIO_SERVICE);
 
        if (AudioManager.RINGER_MODE_NORMAL == audioManager.getRingerMode()) {
            playIt(source.substring(1), volume);
        } else { 
            close(); 
        } 
    } 
    private void playIt(String source, int volume) throws IOException {
        androidPlayer = new MediaPlayer();
        try { 
            String in = openFile(source);
            if (null == in) {
                AssetFileDescriptor afd = JimmActivity.getInstance().getAssets().openFd(source);
                androidPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
            } else { 
                androidPlayer.setDataSource(in);
            } 
            androidPlayer.prepare();
            androidPlayer.setVolume(volume / 100f, volume / 100f);
        } catch (IOException e) {
            close(); 
            throw e;
        } 
    } 
Connect your IDE to all the code out there  Get Codota for Java