Android - Problem Playing Sounds From Assets Folder
i have 5 mp3 files stored on the assets folder. The files are all 25 KB. I load the files using: manager = context.getAssets(); this.inputStream = manager.openFd(fileName).createIn
Solution 1:
After some research i've found the awnser myself. the problem was i was using the following method to set the MediaPlayer's datasource:
inputStream = manager.openFd(fileName).createInputStream();
player.setDataSource(inputStream.getFD());
Wich is just a call to setDataSource(fd, 0, 0x7ffffffffffffffL);
, passing the min offset and this arbitrary length, causing the sounds to be played all mixed.
When using the following code everything worked fine:
AssetFileDescriptor descriptor = manager.openFd(fileName);
long start= descriptor.getStartOffset();
long end= descriptor.getLength();
player.setDataSource(descriptor.getFileDescriptor(), start,end);
Solution 2:
You can also try playing them from the res/raw folder:
MediaPlayer p=MediaPlayer.create(this, R.raw.soundid);
p.start();
Solution 3:
For start try to eliminate one potential problem: compare inputStream with the original file.
Try opening and playing files directly.
Post a Comment for "Android - Problem Playing Sounds From Assets Folder"