开发者

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 advance


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);


You can also try playing them from the res/raw folder:

MediaPlayer p=MediaPlayer.create(this, R.raw.soundid);
p.start();


  1. For start try to eliminate one potential problem: compare inputStream with the original file.

  2. Try opening and playing files directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜