soundpool

SoundPool doesn`t play sound after clicking several times

北慕城南 提交于 2021-02-07 23:41:24
问题 When i click button plays sound on my app, but keep clicking for a while doesn`t play anymore. Maybe it is memory issue? Could you solve me my issue? Here is implemented play sound via SoundPool: when i click button i called play method: and play method works background thread private void play(int resId) { soundPool = buildBeforeAPI21();//TODO: refactor with deprecated constructor soundPool.load(activity, Integer.parseInt(resId), 1); } public SoundPool buildBeforeAPI21() { if (soundPool ==

SoundPool doesn`t play sound after clicking several times

杀马特。学长 韩版系。学妹 提交于 2021-02-07 23:41:21
问题 When i click button plays sound on my app, but keep clicking for a while doesn`t play anymore. Maybe it is memory issue? Could you solve me my issue? Here is implemented play sound via SoundPool: when i click button i called play method: and play method works background thread private void play(int resId) { soundPool = buildBeforeAPI21();//TODO: refactor with deprecated constructor soundPool.load(activity, Integer.parseInt(resId), 1); } public SoundPool buildBeforeAPI21() { if (soundPool ==

SoundPool not playing sound (while MediaPlayer does)

百般思念 提交于 2021-02-05 11:24:23
问题 I am trying to play a sound in an app. However, using SoundPool I am unable to do so. The code is really simple and I don't see where it can fail. A similar code but using MediaPlayer does work, but I am interested in using SoundPool. SoundPool code: private void playSound2(){ SoundPool sp = new SoundPool.Builder().build(); int soundID = sp.load(MainActivity.this, R.raw.sound, 1); sp.play(soundID, 1, 1, 1, 0, 1); } Context: public void goButtonClick(View view){ Button goButton = findViewById

Calling a SoundPool Thead onClickEvent

吃可爱长大的小学妹 提交于 2020-06-13 06:25:07
问题 I'm trying to have a SoundPool play while a view object is being clicked. I have successfully implemented it but found out that the sound of the click will lag. I've been researching on StackOverFlow and on the internet for solutions and the best solution seems to be to have the SoundPool on a separate Thread. I'm very new to the whole Thread thing and so I don't really know what to do at the moment. I have followed THIS guide on creating a SoundPool thread, however, I don't know how to

Android SoundPool 的简单使用

北城余情 提交于 2020-03-24 07:43:41
3 月,跳不动了?>>> 之前只知道Android中可以用MediapLayer播放音乐,原来今天才发现 可以用SoundPool,用 SoundPool 可以播一些短的反应速度要求高的声音, 比如游戏中的爆破声,而 MediapLayer 适合播放长点的。 一般在玩游戏的时候,特别是在射击游戏中,经常会出现“突突突的射击”的声音,听起来好多声音连发的效果。其实实现起来是不难的,都知道,在Java中有线程池的概念,那么,类似的,在 Android 中,也存在 SoundPool 的概念。 备注:声音池默认申请1M的内存空间,所以不适合加载大文件。 SoundPool载入音乐文件使用了独立的线程,不会阻塞UI主线程的操作。但是这里如果音效文件过大没有载入完成,我们调用play方法时可能产生严重的后果,这里Android SDK提供了一个SoundPool.OnLoadCompleteListener类来帮助我们了解媒体文件是否载入完成,我们重载 onLoadComplete(SoundPool soundPool, int sampleId, int status) 方法即可获得。 从上面的onLoadComplete方法可以看出该类有很多参数,比如类似id,是的SoundPool在load时可以处理多个媒体一次初始化并放入内存中,这里效率比MediaPlayer高了很多。

App stops working when I call a second activity with nav drawer from nav drawer click

耗尽温柔 提交于 2020-02-07 03:46:26
问题 Okay so I want to have the navigation drawer available to use from all activities. I am creating a soundboard app and when I click on item 0 on the list I want it to take me to the first activity which has a navigation drawer and the first soundboard activity in it. The from that activity I want to open the nav drawer and click on another item on the list and it can take me to that activity with a soundboard in and so on... I have the nav drawer work fine when the app opens but when I click

Loading SoundPool with audio from APK Expansion file

久未见 提交于 2020-01-25 03:46:15
问题 In the documentation it says: If you're using your expansion files to store media files, a ZIP file still allows you to use Android media playback calls that provide offset and length controls (such as MediaPlayer.setDataSource() and SoundPool.load()). I have 10 small .ogg files and I want to use SoundPool.load (FileDescriptor fd, long offset, long length, int priority) to load these audio files. I've written some code, but when I run it I get error message: "Unable to load sample: (null)" ,

How can I load a sound from the SD Card insted of the raw folder in my Android app useing Soundpool?

て烟熏妆下的殇ゞ 提交于 2020-01-14 04:24:07
问题 I am useing this example to load and play sounds in my Androidapp. I am adding new sounds with mSoundManager.addSound(2, R.raw.sound1); . How can I load a sound from the SD Card insted of the raw folder in my app? 回答1: Have a look at this: http://developer.android.com/reference/android/os/Environment.html#getExternalStorageState() 来源: https://stackoverflow.com/questions/4293122/how-can-i-load-a-sound-from-the-sd-card-insted-of-the-raw-folder-in-my-android-a

The method load(Context, int, int) in the type SoundPool is not applicable, The method getSystemService(String) is undefined

爷,独闯天下 提交于 2020-01-06 05:35:33
问题 Note: I'm kind of a noob so dont really know what these errors mean. This is my class code: package ryan.test; import java.util.HashMap; import android.content.Context; import android.media.AudioManager; import android.media.SoundPool; public class MySingleton { private MySingleton instance; private static SoundPool mSoundPool; private HashMap<Integer, Integer> soundPoolMap; public static final int A1 = 1; private MySingleton() { mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);//

Playing audio file for specific time

▼魔方 西西 提交于 2020-01-05 07:02:34
问题 Guys i able to play audio file using Mediaplayer. But i need to play a audio file for specific time. Eg: play audio1.mp3 till 5 minutes. The audio file is of 10 seconds only.But it should keep playing till 5 minutes. 回答1: try this mediaplayerplayer.setLooping(true);<--- this lets the audio to loop... and this is the countdown timer MyCount counter; Long s1; counter= new MyCount(300000,1000); counter.start(); public void asdf(View v){ <---- method for onclick of buttons pause and resuming