SoundPool problem (sample 1 not READY)

  • Antworten:5
  • Bentwortet
Michele
  • Forum-Beiträge: 1.525

29.04.2013, 10:49:44 via Website

Hallo alle zusammen.

Habe viele Sounds in meinem Programm drin. Die werden per klick
zufällig ausgewählt durch Random und ausgeführt.

1int number = (new Random().nextInt(26) + 1);
2
3 switch (number) {
4
5 case 1:
6 soundID = soundPool.load(this, R.raw.autsch, 1);
7 soundPool.play(soundID, 1.0f, 1.0f, 1, 0, 1f);
8 break;
9
10 case 2:
11 soundID = soundPool.load(this, R.raw.ruepls, 1);
12 soundPool.play(soundID, 1.0f, 1.0f, 1, 0, 1f);
13 break;
14
15 case 3:
16 soundID = soundPool.load(this, R.raw.hahah, 1);
17 soundPool.play(soundID, 1.0f, 1.0f, 1, 0, 1f);
18 break;
19
20 case 4:
21 soundID = soundPool.load(this, R.raw.farts, 1);
22 soundPool.play(soundID, 1.0f, 1.0f, 1, 0, 1f);
23 break;
24
25................. usw bis 26 Sounds.

Aber er zeigt mit das im LogCat an.

Sample 18 not READY. Und das passiert immer wieder.
Samble 19,20,21, und immer weiter not READY.



104-29 10:44:56.180: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
204-29 10:45:38.902: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
304-29 10:45:38.902: V/MediaPlayer(9945): decode(76, 6605638, 63598)
404-29 10:45:38.932: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
504-29 10:45:38.972: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
604-29 10:45:39.572: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
704-29 10:45:39.572: V/MediaPlayer(9945): decode(78, 966813, 851036)
804-29 10:45:39.613: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
904-29 10:45:39.643: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
1004-29 10:45:40.183: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
1104-29 10:45:40.183: V/MediaPlayer(9945): decode(80, 966813, 851036)
1204-29 10:45:40.223: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
1304-29 10:45:40.253: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
1404-29 10:45:40.994: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
1504-29 10:45:41.004: V/MediaPlayer(9945): decode(82, 2060998, 18859)
1604-29 10:45:41.034: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
1704-29 10:46:36.698: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
1804-29 10:46:36.698: V/MediaPlayer(9945): decode(84, 3698178, 29130)
1904-29 10:46:36.738: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
2004-29 10:46:36.768: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
2104-29 10:46:37.549: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
2204-29 10:46:37.549: V/MediaPlayer(9945): decode(86, 21622, 2670)
2304-29 10:46:37.589: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
2404-29 10:46:37.589: E/SoundPool(9945): Unable to load sample: (null)
2504-29 10:46:37.629: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
2604-29 10:46:37.659: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
2704-29 10:46:37.679: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
2804-29 10:46:37.709: E/SoundPool(9945): sample 18 not READY
2904-29 10:46:38.810: V/MediaPlayer(9945): decode(86, 955678, 11086)
3004-29 10:46:38.820: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.
3104-29 10:46:38.850: W/SoundPool(9945): Sample was not loaded. Waiting for 30ms.

Wo liegt das problem?
Er spielt viele ab aber manche wohl auch nicht durch das "sample XX not READY"


LG

— geändert am 29.04.2013, 11:05:54

Antworten
Michele
  • Forum-Beiträge: 1.525

29.04.2013, 12:55:48 via Website

Hallo.


Also habe die Sounds wirklich soooo klein Konvertiert wie es nur geht.

Und komischerweise gehts nun oder ich bilde mir das ein?


Hoffe jemand kann mir da weiterhelfen bei dem Fehler.


LG

Antworten
Mac Systems
  • Forum-Beiträge: 1.727

29.04.2013, 14:20:04 via Website

Ohne das genau zu wissen. Ich denke es liegt daran das die Sounds on demand geladen werden. Evtl passiert das Asynchron und du solltest diese entsprechend vorladen und nur noch anhand der ID abspielen. So habe ich das immer gemacht und es lief dann auch ohne Probleme.

Das liesse sich dann so lösen:

1public final class SoundManager
2{
3
4 private final static int DEFAULT_PRIORITY = 1;
5 private final static int NO_LOOP = 0;
6 private final static float PLAYBACK_SPEED = 1f;
7
8 private final SoundPool soundPool;
9 private final AudioManager audioManager;
10
11 private final Context context;
12
13 private final int chat_click_sound_id;
14
15 private final int camera_sound_id;
16
17 private final int incoming_share_id;
18
19
20 /**
21 *
22 * @param theApplicationContext
23 */
24 public SoundManager(@Nonnull final Context theApplicationContext)
25 {
26 Preconditions.checkNotNull(theApplicationContext, "Context");
27 //
28 context = theApplicationContext;
29 soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
30 audioManager = (AudioManager) theApplicationContext.getSystemService(Context.AUDIO_SERVICE);
31 //
32 final int temp_chat_click_sound_id = soundPool.load(context, R.raw.chat_click, DEFAULT_PRIORITY);
33 Preconditions.checkArgument(0 < temp_chat_click_sound_id, "failed to load chat sound");
34 //
35 final int temp_camera_sound_id = soundPool.load(context, R.raw.camera_click, DEFAULT_PRIORITY);
36 Preconditions.checkArgument(0 < temp_chat_click_sound_id, "failed to load camera sound");
37 //
38 final int temp_incoming_share_id = soundPool.load(context, R.raw.incoming_share, DEFAULT_PRIORITY);
39 Preconditions.checkArgument(0 < temp_incoming_share_id, "failed to load incoming sharesound");
40
41 //
42 chat_click_sound_id = temp_chat_click_sound_id;
43 camera_sound_id = temp_camera_sound_id;
44 incoming_share_id = temp_incoming_share_id;
45 }
46
47
48 public void playPhotoTakenSound()
49 {
50 playSound(camera_sound_id);
51 }
52
53
54 public void playChatClickSound()
55 {
56 playSound(chat_click_sound_id);
57 }
58
59
60 public void playIcomingShareSound()
61 {
62 playSound(incoming_share_id);
63 }
64
65
66 /**
67 * Plays the sound with given ID
68 *
69 * @param soundID
70 */
71 private void playSound(final int soundID)
72 {
73 float streamVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
74 streamVolume = streamVolume / audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
75 soundPool.play(soundID, streamVolume, streamVolume, DEFAULT_PRIORITY, NO_LOOP, PLAYBACK_SPEED);
76 }
77
78}

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Michele

Antworten
Michele
  • Forum-Beiträge: 1.525

29.04.2013, 14:23:17 via Website

Uffff danke dir sehr.

Aber das bei 50 Sounds so machen?

Ohaa das wird ein riesen block Code :grin:



LG

Antworten
Mac Systems
  • Forum-Beiträge: 1.727

29.04.2013, 14:25:24 via Website

Du solltest überlegen ob das bei 50 sounds noch sinn macht, Das system schmeisst die APP schnell aus dem RAM wenn sie zuviel verlangt, Bzw. du bekommst OOM Errors. Der MediaPlayer ist eine Alternative.

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Antworten
Michele
  • Forum-Beiträge: 1.525

29.04.2013, 14:30:16 via Website

Der MediaPlayer ist für sowas nicht gut finde ich.
Denn irgendwann spielt er gar keine halt mehr ab nach zu vielen drücken auf dem Button.

Deswegen mag ich den SoundPool.
Mit dem hatte ich noch nie so große Probleme bei so einen massen Haufen Sounds.

Ich Konvertiere die Sounds ja schon Extrem klein damit das ja nicht passiert.

Ich werde dein beispiel mal testen und weiter rum testen. Zurzeit geht ja alles seit ich die Sounds extrem klein gemacht
habe.



LG

— geändert am 29.04.2013, 14:32:50

Antworten