[ACCEPTED]-How do you play Android InputStream on MediaPlayer?-fileoutputstream
Accepted answer
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();
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
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.