[ACCEPTED]-How do you play Android InputStream on MediaPlayer?-fileoutputstream

Accepted answer
Score: 17

Fixed it. Turns out that after writing the 5 buffer in the temporary file created by 4 "File," you can then open that file using 3 a FileInputStream, then proceed to play 2 it shown below. Thanks for all your help 1 guys.

mp = new MediaPlayer();

FileInputStream fis = new FileInputStream(convertedFile);
mp.setDataSource(fis.getFD());

Toast.makeText(this, "Success, Path has been set", Toast.LENGTH_SHORT).show();

mp.prepare();
mp.start();
Score: 2

This is the code that worked for me

//preserved to stop previous actions 
MediaPlayer lastmp;

public void playSound(String file) {
    try {
        if (lastmp!=null) lastmp.stop();
        MediaPlayer mp = new MediaPlayer();
        lastmp = mp;
        AssetFileDescriptor descriptor;

        AssetManager assetManager = act.getAssets();

        descriptor =  assetManager.openFd(fileName);
        mp.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
        descriptor.close();
        mp.prepare();
        mp.start();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

the file 1 shoud be on the assets folder

More Related questions