×

Discussion Board

Results 1 to 2 of 2

Thread: Sounds in 7650

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    47

    Sounds in 7650

    Hi all


    I am again asking this question in this forum

    I am developing a game for Nokia Series 60 for the Nokia mobile 7650. Using the J2ME and Sun ONE Studio for Mobile.

    Can some body shows me how to make 7650 make sounds in J2ME.


    Shahzad

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    382

    RE: Sounds in 7650

    Hello

    Here is one example for you where .ott file is loaded and played:
    also playing note are introduced,
    notice that .ott file is places into classes folder in this case.
    could be also res folder when making package.

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import com.nokia.mid.sound.*;
    import java.io.ByteArrayOutputStream;
    import java.io.InputStream;

    public class Ring extends MIDlet implements CommandListener
    {
    private Display display = null;
    private List list = null;

    private Sound sound = null;

    private final static byte[] BYTES =
    {
    (byte)0x02, (byte)0x4a, (byte)0x3a, (byte)0x69,
    (byte)0x8c, (byte)0xe9, (byte)0x71, (byte)0x99,
    (byte)0xbd, (byte)0xc9, (byte)0xd5, (byte)0xb5,
    (byte)0xb9, (byte)0xbc, (byte)0x04, (byte)0x00,
    (byte)0x10, (byte)0xd9, (byte)0x65, (byte)0x13,
    (byte)0x82, (byte)0x4c, (byte)0x40, (byte)0x8c,
    (byte)0x09, (byte)0xc4, (byte)0x00
    };

    private final static String PATH = "/some_name.ott";

    public Ring()
    {
    list = new List("Sound in MIDP", List.IMPLICIT);
    list.append("Play Ott File", null);
    list.append("Play Binary Array", null);
    list.setCommandListener(this);
    }

    protected void destroyApp(boolean p0) throws MIDletStateChangeException {}

    protected void startApp() throws MIDletStateChangeException
    {
    Display.getDisplay(this).setCurrent(list);
    }


    protected void pauseApp() {}

    public void commandAction (Command c, Displayable d)
    {
    if(c == List.SELECT_COMMAND)
    {
    if(list.getSelectedIndex() == 0)
    {
    System.out.print("Playing Ott File"
    try
    {
    InputStream tune = this.getClass().getResourceAsStream("/brianboru.ott"
    byte[] buffer = new byte[100000];
    tune.read(buffer, 0, buffer.length);
    sound = new Sound(buffer, Sound.FORMAT_TONE);
    sound.init(buffer, Sound.FORMAT_TONE);
    sound.play(1);
    } catch (Exception e) {}
    }

    if(list.getSelectedIndex() == 1)
    {
    System.out.print("Playing Binary Array"
    sound = new Sound(BYTES, Sound.FORMAT_TONE);
    sound.init(BYTES, Sound.FORMAT_TONE);
    sound.play(2);
    }
    }
    }

    }

    The WAV files ca be played also by:
    try
    {
    InputStream tune = this.getClass().getResourceAsStream("/somefile.wav"
    byte[] buffer = new byte[100000];
    tune.read(buffer, 0, buffer.length);
    sound = new Sound(buffer, Sound.FORMAT_WAV);
    sound.init(buffer, Sound.FORMAT_WAV);
    sound.play(2);
    buffer = null;
    } catch (Exception e) {}

    Mobile Media API enabales also play MIDI files.

    I hope this help you

Posting Permissions

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