Problems playing MP3s

All your problems with Audio, Video and Images.

Problems playing MP3s

Postby pwndrian » Thu Oct 08, 2009 12:04 pm

Hello,

I'm desperately trying to get my soundboard application to work. I have a GridView consisting of Buttons, which have an OnClickListener starting the sound file associated with the button. The sound files are stored as MP3 audio files in the res/raw folder and are referenced using the R class.

The following problem only occurs when running the app on a real device, however, on the emulator it works perfectly. I have tried two different HTC Hero so far.

I have a mysterious problem, that everytime I press a button to play a specific sound, ALL sounds in the res/raw folder are played in the order they are listed there. My current code to play a sound looks like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if (player != null) {
  2.  
  3.         player.stop();
  4.  
  5.         player.release();
  6.  
  7. }
  8.  
  9.  
  10.  
  11. player = MediaPlayer.create(this, resId);
  12.  
  13.  
  14.  
  15. if (player != null) {
  16.  
  17.         player.start();
  18.  
  19. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


As you can see I use a "singleton" MediaPlayer to play the files. I have also tried using a new separate MediaPlayer instance for each sound file, with the same result. Additionally, I have tried playing the sound file in a separate thread with the result, that only the first time all sound files are played. After that the buttons work as intended.

Thanks for your help!
Adrian
pwndrian
Freshman
Freshman
 
Posts: 2
Joined: Thu Oct 08, 2009 11:40 am

Top

Postby azraeal » Thu Oct 08, 2009 6:06 pm

Please post your the code following up to playback, including the click listener.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby pwndrian » Thu Oct 08, 2009 7:54 pm

You can take a look at the source code on the Google Code project site.
pwndrian
Freshman
Freshman
 
Posts: 2
Joined: Thu Oct 08, 2009 11:40 am

Postby drkow19 » Wed Oct 28, 2009 3:43 am

Where it says resId you need to put "R.raw.song" if your song is in the res/raw folder and is named song.mp3.
drkow19
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Oct 28, 2009 3:41 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 14 guests