soundpool

How to make Random sound when button click?

[亡魂溺海] 提交于 2019-12-13 21:05:18
问题 So i have 4 sound here, i was use SoundPool sound1 = soundPool.load(this, R.raw.aww, 1); sound2 = soundPool.load(this, R.raw.arh, 1); sound3 = soundPool.load(this, R.raw.agg, 1); sound4 = soundPool.load(this, R.raw.uhh, 1); so i wonder how to make button choose random sound : click= (Button)findViewById(R.id.bm); click.setOnClickListener(new View.OnClickListener() { public void onClick(View click){ //choose one of four sound to play } }); } Anyone have some Idea? 回答1: You can store soundIDs

SoundPool sound stops only once?

给你一囗甜甜゛ 提交于 2019-12-13 16:23:31
问题 I have a Sound class: package dubpad.brendan; import android.media.SoundPool; public class Sound { SoundPool soundPool; int soundID; public Sound(SoundPool soundPool, int soundID) { this.soundPool = soundPool; this.soundID = soundID; } public void play(float volume) { soundPool.play(soundID, volume, volume, 0, -1, 1); } public void stop(int soundID){ soundPool.stop(soundID); } public void dispose() { soundPool.unload(soundID); } } and I have an activity that extends a button : package dubpad

How to mute a soundpool?

怎甘沉沦 提交于 2019-12-13 02:27:07
问题 I want to allow the user to mute the app with a button and someone advised me to ''stick a boolean on your MediaPlayerPool that you set to false when the mute button is pressed. Then in your playSound method, do nothing if the value is false.''but i dont know how to do that. Could someone post an example code pls. The pool code : public class MediaPlayerPool { private static MediaPlayerPool instance = null; private Context context; private List<MediaPlayer> pool; public static MediaPlayerPool

(Android) How to tell if a sound is playing in soundpool

旧时模样 提交于 2019-12-12 13:09:29
问题 Is there a way I can tell if a certain sound is playing in SoundPool??? I.E. if(MySound./*Command Goes Here*/()==true{ //Do stuff } I would appreciate if you could point me in the right direction or give me the code. I am not able to find any thing that does this on the docs. 回答1: This is not possible using SoundPool . See Android SoundPool: get notified when end of played for two other ideas: Use MediaPlayer , which provides an OnCompletionListener , instead of SoundPool Use MediaPlayer in

Android Low latency Audio using SoundPool

蹲街弑〆低调 提交于 2019-12-12 04:35:37
问题 I want to play a simple short tone (150ms) with as low latency as possible. Reading around it seems that the simplest solution is to use SoundPool. I've also read that in Android 4.1 support for OpenSL ES was introduced, which uses a lower latency audio output path. http://source.android.com/devices/latency_design.html So my question is does SoundPool make use of this low latency audio path? Or is the only way to access this feature via OpenSL ES and the NDK? 来源: https://stackoverflow.com

SoundPool crashes in two scenarios. Code for first scenario crashes

帅比萌擦擦* 提交于 2019-12-12 04:18:00
问题 @Ian G. Clifton Here is the code for the first type of soundpool I tried. when the button to load the activity the program FCs back to the previous activity. code starts here but it doesn't transfer over:::::: 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

When I compile Java(fx) application for Android, with the SoundPool use, the java compiler says “package android.media does not exist”

廉价感情. 提交于 2019-12-12 01:39:38
问题 In a Java application for Android, made in JavaFX under Eclipse Neon2, I want to use the android media SoundPool class. To do that, I have added, in the Java Build Path: the android-sdks platform : android-25 (called android.jar). the jfxdvk-8.60.8.jar Then, for instance, I create a SoundPool instance as follows: import android.media.SounPool; import android.media.MediaPlayer; ... SoundPool sp = new SoundPool(MAX_STREAMS,AudioManager.STREAM_MUSIC,0); The syntax is correct and the Eclipse

SoundPool not playing after 3 second of opening my activity

有些话、适合烂在心里 提交于 2019-12-11 13:39:23
问题 I am trying to play a sound when a user clicks on a button, This works well if I click the button wothin the first 3-5 seconds of when the activity is open however if I wait more then 3-5 seconds there is no sound. I am also not getting any error regarding the sound.... Any ideas would be appriciated! UPDATE: This is happening only on my HTC. If I try this on a Samsung Galaxy S 2 it works fine!!!! In my logcat is says: "AudioHardwareQSD: AudioHardware pcm playback is going to standby" any

How to implement release function in soundpool?

試著忘記壹切 提交于 2019-12-11 10:35:20
问题 hy,,im newbie for android,i have error AudioFlinger could not create track, status: -12 when running my application. i read for use release() method for fix it, but i don't know how to implement on my code, please help me ?? this is my code,please fix it :) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.talempong); this.setVolumeControlStream(AudioManager.STREAM_MUSIC); spool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);