Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User shahzad73's Avatar
    Join Date
    Mar 2003
    Posts
    47
    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
    Regular Contributor wangkui35's Avatar
    Join Date
    Mar 2003
    Location
    Tampere / Finland
    Posts
    201
    Hi,

    MIDP 1.0 doesn't support sound by default, but you can use Nokia UI API or MMAPI to edit or play sounds in different foramts.

    Currently, Nokia 7650 only supports Nokia UI API, here is example codes playings different sounds formats, some formats may work differently between Emulator and physical devices.

    When use these codes, remember to replace the resource files (wav file and ott file) with your own.

    ----------------------------------------------------------------------

    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 = "/brianboru.ott";

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

    int[] format = sound.getSupportedFormats();
    for (int i = 0; i < format.length; i++)
    System.out.println("The supported formats include1 - FORMAT_TONE, 5 - FORMAT_WAV) " + format[i]);

    System.out.println(System.getProperty("microedition.locale&quot); // return the language code and the country code
    System.out.println(System.getProperty("microedition.profiles&quot); // return the Profiles
    System.out.println(System.getProperty("microedition.platform&quot); // return the model and software version of the phone



    }

    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[500];
    tune.read(buffer, 0, buffer.length);
    sound = new Sound(buffer, Sound.FORMAT_TONE);
    sound.init(buffer, Sound.FORMAT_TONE);
    sound.play(1);
    buffer = null;
    } 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(1);
    }

    if(list.getSelectedIndex() == 2)
    {
    System.out.print("Playing talkforever16 WAV file"
    try
    {
    InputStream tune = this.getClass().getResourceAsStream("/talkforever16.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(1);
    buffer = null;
    } catch (Exception e) {}
    }

    if(list.getSelectedIndex() == 3)
    {
    System.out.print("Playing Note"
    sound = new Sound(1000, 1000);
    sound.init(1000, 1000);
    sound.play(1);
    }
    }
    }

    }

    ----------------------------------------------------------------------

    Regards,
    Kui Wang/Forum Nokia

  3. #3
    Registered User shahzad73's Avatar
    Join Date
    Mar 2003
    Posts
    47
    hi Kui


    Thanks for the reply....

    Kui i have tried your code... but i am getting error while making the package in Sun Studio ONE. Also problem seems to be with

    import com.nokia.mid.sound.*;


    i mean there is no such package. when write . after com then in the list i do not get the nokia package.

    what did i do was that copy your code in my file in Sun Studio. change the names of the class name and constructor. copy a WAV file and add it my resources. change the name in the code then compile. compilation is okey. but when i create the package.. there is a error... prevarifyer error... error prevarifying class...

    why the package Nokia is not visible.



    Shahzad

  4. #4
    Regular Contributor wangkui35's Avatar
    Join Date
    Mar 2003
    Location
    Tampere / Finland
    Posts
    201
    Hello Shahzad,

    Nokia UI API is included in all the Nokia Java phone emulators, you have to first download a phone SDK from Forum Nokia website and integrate it with Sun ONE studio.

    In order to run nokia emulators with Sun ONE studio, you should install emulators into the following folder:

    <your Sun ONE studio install directory>\emulator\J2MEWTK-1_0_4-win\wtklib\devices

    Then you should find nokia emulators under Explorer-Runtime-Device Emulaotr Registry-installed Emulators-J2ME Wireless Toolkit 1.0.4 folder.

    Still, please pay attention to the size of your wav file. In case it's too big, you have to enlarge the buffer to play the wav file (I set the buffer to 100k in the source codes). The buffer should be big enoung to play the wav file.

    The code fraction:
    ----------------------------------------------------------------------
    int[] format = sound.getSupportedFormats();
    for (int i = 0; i < format.length; i++)
    System.out.println("The supported formats include1 - FORMAT_TONE, 5 - FORMAT_WAV) " + format[i]);
    ----------------------------------------------------------------------
    is used to test which formats the phone or emulator supports, if you run the codes in emulator, you can read the resluts from the output window. But unfortunately, the real 7650 seems not to support it, you have to "comment" this part in order to test the codes in Nokia 7650.

    Regards,
    Kui Wang /Forum Nokia

  5. #5
    Registered User shahzad73's Avatar
    Join Date
    Mar 2003
    Posts
    47
    HI Kui Wang

    I'm afraid to say that i have done this before.. i have instatted the Series 60 Phone SDK in the directory you mention. that how i am developing applications for 7650. There is another obervation i did that

    sound = new Sound(1000, 1000);
    sound.init(1000, 1000);
    sound.play(1);


    code did compiled and packages... but when i run the emulator then it gives error that unable to load the sound class some thing like that.... but my package was created with this code and the import statement above.


    any other suggestion

    Shahzad

  6. #6
    Regular Contributor wangkui35's Avatar
    Join Date
    Mar 2003
    Location
    Tampere / Finland
    Posts
    201
    Hello,

    The old Nokia Series 60 MIDP SDK for Symbian OS does not support playing sounds very well, you can try to use the Series 60 Concept SDk to test the codes. The MIDlet can run very well with the Series 60 Concept SDK except the Note format can't be played, Other emulators like 7210 and 3510i can play Note format.

    (I use the JBuilder7 + MobileSet3 to test the codes)

    Regards,
    Kui Wang/Forum Nokia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved