SoundManager Length

Put your problem here if it does not fit any of the other categories.

SoundManager Length

Postby wahid2oo9 » Sat Jan 15, 2011 2:57 am

I have a problem, I'm tryna figure out where the code is or where to enter the code for the length of the sound I added.

Does it go in the class i created example.java or in soundmanager.java

What I have at the moment is I touch the screen and I get a sound that just plays 5seconds and cuts out the rest.

this is Soundmanager.java
package com.example.sound;

import java.util.HashMap;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;



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(1, 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);
}

public void playLoopedSound(int index) {

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

}


and this is example.java

package com.example.sound;

import com.example.sound.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Beep extends Activity {
private SoundManager mSoundManager;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());
mSoundManager.addSound(1, R.raw.beep);

Button SoundButton = (Button)findViewById(R.id.PanicButton);
SoundButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
mSoundManager.playSound(1);

}
});
}}


Please help,

Thanks
Wahid
wahid2oo9
Developer
Developer
 
Posts: 36
Joined: Fri Dec 31, 2010 7:07 am

Top

Re: SoundManager Length

Postby wahid2oo9 » Thu Jan 20, 2011 10:29 am

anyone help ?
wahid2oo9
Developer
Developer
 
Posts: 36
Joined: Fri Dec 31, 2010 7:07 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests