×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    8

    nokiaUI sound problem with MIDP 1.0 on Ngage

    Hi Folks,
    Im really stuck at this:
    I have developped a game completely in MIDP 1.0. Now I want to have all these nice feats of the Nokia UI. I downloaded
    the Nokia_7210_MIDP_SDK_v1_0
    to compile and test my application.
    FullScreen is working fine on my Ngage Phone and on all the emulators.
    When I try to use Sound,( just started with playing a tone. (Sound play( freq, duration )))
    it does work on the emulator, i can hear a nice beep. BUT it DOES NOT work on the Ngage phone. Though the play function is called, i cant hear the sound.
    In other apps the sound does work so it is not because the Sound is Off.
    Does anyone have an idea about whats going on ? Im implementing the sound just like its shown in the Tones Documentation from forum nokia:

    This method is used to load a toneplayer
    The TonePlayer is just an empty dummy
    NokiaTonePlayer is a subClass of toneplayer which ueses the NOKIA UI .
    and has a "Sound" variable, played via
    snd.play(440,2000L);
    *****
    public static TonePlayer makeTonePlayer(){

    TonePlayer player;

    try {

    // This statement throws an exception if no Nokia UI API available

    Class.forName("com.nokia.mid.sound.Sound");

    // If we get here, Nokia UI API is available, so we can safely
    // create a player that uses it. But we use Class.forName rather
    // than 'new' so that there is no link dependency.

    Class clas = Class.forName("scim.bd.NokiaTonePlayer");

    player = (TonePlayer)(clas.newInstance());

    using = "Nokia";

    }catch (Exception e) {

    // If no Nokia UI API, then create a dummy tone player
    player = new TonePlayer();

    using = "default";

    }

    return player;
    }
    *****
    In my game the nokia Player is actually used. ( using is always set to "Nokia" on both phone and emulators)
    But still i hear no beep on the Phone.
    Does anybody have an idea? or maybe a peace of functional code( I'm Using MIDP 1.0 )
    big thx in advance
    .ilya

  2. #2
    Registered User
    Join Date
    Nov 2003
    Location
    Switzerland
    Posts
    34
    im using this now for NGage and tones (loaded from OTT files) and works fine even with multiple sounds,
    check the sound.init() function, thats what i believe you are missing:


    import java.io.*;
    import com.nokia.mid.sound.*;
    import java.io.ByteArrayOutputStream;
    import java.io.InputStream;

    class SoundEffects
    {
    private static SoundEffects instance;
    private MainCanvas pParent;

    private Thread dThread; // Use a thread with the media player
    private boolean disMTime, interrupted;
    private String mtime;

    private Sound sound = null;
    int nloop = 1;
    byte[] mBuf;

    public SoundEffects(MainCanvas p, String file)
    {
    pParent = p;
    createPlayer(file);
    this.setVolume(pParent.master_volume);

    }
    void Stop()
    {
    sound.stop();
    }
    void close()
    {
    if( sound != null )
    sound.release();
    }
    void setLoopCount(int loopcount)
    {
    nloop = loopcount;
    }
    void startGenericSound()
    {
    try
    {
    sound.init(mBuf, Sound.FORMAT_TONE);
    this.setVolume(pParent.master_volume);
    sound.play(1);
    }
    catch (Exception e) {e.printStackTrace();}

    }

    void setVolume(int volume)
    {
    volume = (((255<<8)/100)*volume);
    sound.setGain(volume>>8);
    //sound.setGain(255);
    }

    private void createPlayer( String filename )
    {
    try
    {
    int numbytes = 0;
    InputStream tune = this.getClass().getResourceAsStream(filename);
    while(tune.read()!=-1)
    numbytes++;
    tune = this.getClass().getResourceAsStream(filename);
    mBuf = new byte[numbytes];
    tune.read(mBuf,0,mBuf.length);
    sound = new Sound(mBuf, Sound.FORMAT_TONE);

    }
    catch( Exception e )
    {
    e.printStackTrace();
    }
    }

    public void ReplayIfStopped()
    {
    int state = sound.getState();
    if( state == Sound.SOUND_STOPPED ||
    state == Sound.SOUND_UNINITIALIZED )
    startGenericSound();
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×