0

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

marcosbeirigo
  • 11,098
  • 6
  • 39
  • 57

3 Answers3

2

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

MediaPlayer p=MediaPlayer.create(this, R.raw.soundid);
p.start();
Baz
  • 36,440
  • 11
  • 68
  • 94
GeekYouUp
  • 1,651
  • 11
  • 10
2

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);
marcosbeirigo
  • 11,098
  • 6
  • 39
  • 57
0
  1. For start try to eliminate one potential problem: compare inputStream with the original file.

  2. Try opening and playing files directly.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154