Dark Blood Studios
- Forum-Beiträge: 203
20.12.2011, 16:47:29 via Website
20.12.2011 16:47:29 via Website
Hi, kann man irgendwie zwei Sounds z.B. ogg zu einem zusammenfügen? Also ich will sie nicht hintereinnander machen sonder gleichzeitig.
Und wie kann ich mehrere Sounds gleichzeitig abspielen? Mit Soundpool hört sich dass irgendwie seltsam an. Hier mal mein Code wie ich es bis jetzt versucht habe:
Und wie kann ich mehrere Sounds gleichzeitig abspielen? Mit Soundpool hört sich dass irgendwie seltsam an. Hier mal mein Code wie ich es bis jetzt versucht habe:
1private float volume;
2private SoundPool soundPool;
3private HashMap<Integer, Integer> soundPoolMap;
4private Thread thread = new Thread(this);
5
6public init() {
7 Context context = getApplicationContext();
8
9 soundPool = new SoundPool(200, AudioManager.STREAM_MUSIC, 100);
10 soundPoolMap = new HashMap<Integer, Integer>();
11 soundPoolMap.put(1, soundPool.load(context, R.raw.sound_1, 100));
12 soundPoolMap.put(2, soundPool.load(context, R.raw.sound_2, 100));
13 soundPoolMap.put(3, soundPool.load(context, R.raw.sound_3, 100));
14 soundPoolMap.put(4, soundPool.load(context, R.raw.sound_4, 100));
15 soundPoolMap.put(5, soundPool.load(context, R.raw.sound_5, 100));
16 soundPoolMap.put(6, soundPool.load(context, R.raw.sound_6, 100));
17 soundPoolMap.put(7, soundPool.load(context, R.raw.sound_7, 100));
18 soundPoolMap.put(8, soundPool.load(context, R.raw.sound_8, 100));
19 soundPoolMap.put(9, soundPool.load(context, R.raw.sound_9, 100));
20 soundPoolMap.put(10, soundPool.load(context, R.raw.sound_10, 100));
21 soundPoolMap.put(11, soundPool.load(context, R.raw.sound_11, 100));
22
23 AudioManager mgr = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
24 float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
25 float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
26 volume = streamVolumeCurrent / streamVolumeMax;
27
28 thread.start();
29}
30
31public void run() {
32 soundPool.play(soundPoolMap.get(1), volume, volume, 1, 0, 1f);
33 soundPool.play(soundPoolMap.get(2), volume, volume, 1, 0, 1f);
34 soundPool.play(soundPoolMap.get(3), volume, volume, 1, 0, 1f);
35 soundPool.play(soundPoolMap.get(4), volume, volume, 1, 0, 1f);
36}
2private SoundPool soundPool;
3private HashMap<Integer, Integer> soundPoolMap;
4private Thread thread = new Thread(this);
5
6public init() {
7 Context context = getApplicationContext();
8
9 soundPool = new SoundPool(200, AudioManager.STREAM_MUSIC, 100);
10 soundPoolMap = new HashMap<Integer, Integer>();
11 soundPoolMap.put(1, soundPool.load(context, R.raw.sound_1, 100));
12 soundPoolMap.put(2, soundPool.load(context, R.raw.sound_2, 100));
13 soundPoolMap.put(3, soundPool.load(context, R.raw.sound_3, 100));
14 soundPoolMap.put(4, soundPool.load(context, R.raw.sound_4, 100));
15 soundPoolMap.put(5, soundPool.load(context, R.raw.sound_5, 100));
16 soundPoolMap.put(6, soundPool.load(context, R.raw.sound_6, 100));
17 soundPoolMap.put(7, soundPool.load(context, R.raw.sound_7, 100));
18 soundPoolMap.put(8, soundPool.load(context, R.raw.sound_8, 100));
19 soundPoolMap.put(9, soundPool.load(context, R.raw.sound_9, 100));
20 soundPoolMap.put(10, soundPool.load(context, R.raw.sound_10, 100));
21 soundPoolMap.put(11, soundPool.load(context, R.raw.sound_11, 100));
22
23 AudioManager mgr = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
24 float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
25 float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
26 volume = streamVolumeCurrent / streamVolumeMax;
27
28 thread.start();
29}
30
31public void run() {
32 soundPool.play(soundPoolMap.get(1), volume, volume, 1, 0, 1f);
33 soundPool.play(soundPoolMap.get(2), volume, volume, 1, 0, 1f);
34 soundPool.play(soundPoolMap.get(3), volume, volume, 1, 0, 1f);
35 soundPool.play(soundPoolMap.get(4), volume, volume, 1, 0, 1f);
36}
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.