Android - Problem playing sounds from assets folder
i have 5 mp3 files stored on开发者_Go百科 the assets folder. The files are all 25 KB.
I load the files using:manager = context.getAssets();
this.inputStream = manager.openFd(fileName).createInputStream();
Whenever i try to play the files, the sounds are all messed up like they were mixed or something. I've zipaligned the app already but with no results.
anny help about this issue? Thanks in advanceAfter 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);
You can also try playing them from the res/raw folder:
MediaPlayer p=MediaPlayer.create(this, R.raw.soundid);
p.start();
For start try to eliminate one potential problem: compare inputStream with the original file.
Try opening and playing files directly.
精彩评论