Soundboard playback issues

All your problems with Audio, Video and Images.

Soundboard playback issues

Postby Slimtech » Tue Jun 22, 2010 8:38 pm

Hello everyone, new developer here and new to all of this programming as well. I am currently making a soundboard (I know, there are too many on the market) and I have run into a problem.

Currently I am using the tutorial from http://www.myandroidsoundboard.com/Droid2.htm and everything seems to be working fine except 1 file. I am trying to play a theme song from a tv show in a .ogg file and it will play for 3 seconds and stop. All the rest 29 out of 30 files play if not short of 1-2 seconds from the end.

A sample of my code from the soundboardmanager.java:

public class SoundManager {

private SoundPool mSoundPool;
private HashMap<Integer, Integer> mSoundPoolMap;
private AudioManager mAudioManager;
private Context mContext;


public SoundManager()
{

}

public void initSounds(Context theContext) {
mContext = theContext;
mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap<Integer, Integer>();
mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
}

public void addSound(int Index,int SoundID)
{
mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1));

}

public void playSound(int index) {

int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);
}

}



Any help would be greatly appreciated. From another site when I was working on this before I gave up in the past suggested this code:

Add MediaPlayer FilmSound;

just under your class

public class Soundboard extends Activity {
MediaPlayer FilmSound;

like so, remembering to import the media player with ctrl shift and o

then add

Button dollar = (Button)findViewById(R.id.Dollar);
FilmSound = MediaPlayer.create(getApplicationContext(), R.raw.buythat);
dollar.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (FilmSound.isPlaying())
{
FilmSound.stop();
FilmSound.reset();
FilmSound = MediaPlayer.create(getApplicationContext(), R.raw.buythat);
FilmSound.start();
}
else {
FilmSound = MediaPlayer.create(getApplicationContext(), R.raw.buythat);
FilmSound.start(); }
}
});

dollar being the button id, so change to your own, for some odd reason, my code needs to have the film sound variable three times for one of the sound samples, otherwise crashes out.
You can now use samples at any rate you like.



Thanks again for any help that can be offered!!
Slimtech
Freshman
Freshman
 
Posts: 3
Joined: Tue Jun 22, 2010 5:48 pm

Top

Re: Soundboard playback issues

Postby Slimtech » Tue Jun 22, 2010 8:44 pm

The second sample of code, I tried to add that and failed.
Slimtech
Freshman
Freshman
 
Posts: 3
Joined: Tue Jun 22, 2010 5:48 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google Feedfetcher and 9 guests