Shalini
Shalini

Reputation: 161

How to fix Media Exception in Nokia device(J2me)

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?

Upvotes: 3

Views: 521

Answers (2)

frayab
frayab

Reputation: 2512

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);

Upvotes: 4

COD3BOY
COD3BOY

Reputation: 12092

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.

Upvotes: 2

Related Questions