3

I am developing a game in J2ME and I am using 4 different sound(midi) files in game. When I run this game on nokia device, it's showing too many players prefetched exception. It's working fine in Samsung. How to resolve this?

frayab
  • 2,512
  • 20
  • 25
Shalini
  • 151
  • 1
  • 2
  • 9
  • You must accept answer for helping future views of the question. @shalini you have to click on the green tick of the correct answer. – frayab Jan 26 '12 at 12:46

2 Answers2

4

I had the same problem and solved implementing a PlayerListener and deallocating sounds after play:

  playbackPlayer = Manager.createPlayer(ttsConnection.getFileUrl());
  PlayerListener pl = new PlayerListener() {

      public void playerUpdate(Player player, String event, Object eventData) {
          if (event.equalsIgnoreCase(PlayerListener.END_OF_MEDIA)
                  || event.equalsIgnoreCase(PlayerListener.STOPPED)) {
              player.close();
          }

      }
  };
  playbackPlayer.addPlayerListener(pl);
gnat
  • 6,213
  • 108
  • 53
  • 73
frayab
  • 2,512
  • 20
  • 25
2

Cause :

Many devices have limits of how many sounds can be in the prefetched state at once.This differ with devices. On many S60s, for example, it's six ,on many other devices, it is only one.

Possible Solutions :

  • Realize the players, but don't prefetch them - they'll be prefetched automatically when they play.

  • use a PlayerListener to deallocate the players after they play, to avoid holding too many in the prefetched state.

COD3BOY
  • 11,964
  • 1
  • 38
  • 56