×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    4

    help!!! urgent.. i'm having problem playing sound in 7650

    i can't play sound in 7650 but using the same code, it actually works with 3650.

    help.. i used the Sound class in nokia api

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    8

    Me too

    Pls help. Thanks so much.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    10

    hi

    Is this code OK ? Do you want play WAVE or ringtone sound ?
    This code is reserved for WAVE.

    InputStream tune;
    byte buffer[];
    Sound sound;
    tune = this.getClass().getResourceAsStream("/Dragon1/res/scn/punch1.wav");
    buffer = new byte[3590]; // 3590 is the file size
    tune.read(buffer, 0, buffer.length);
    sound = new Sound(buffer, Sound.FORMAT_WAV);
    sound.init(buffer, Sound.FORMAT_WAV);
    sound.play(1);

    The following code is used for ringtone sound
    byte music[] = {
    (byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x51,
    (byte)0x35, (byte)0xA5, (byte)0x91, (byte)0xA4,
    (byte)0x04, (byte)0x00, (byte)0x3F, (byte)0x1E,
    (byte)0x96, (byte)0x20, (byte)0xE3, (byte)0x12,
    (byte)0x45, (byte)0x28, (byte)0x30, (byte)0xC4,
    (byte)0x98, (byte)0x49, (byte)0x16, (byte)0x15,
    (byte)0x41, (byte)0x36, (byte)0x15, (byte)0x61,
    (byte)0x14, (byte)0x20, (byte)0xC2, (byte)0x12,
    (byte)0x45, (byte)0x06, (byte)0x90, (byte)0x61,
    (byte)0x05, (byte)0x58, (byte)0x59, (byte)0x86,
    (byte)0x0A, (byte)0x83, (byte)0x08, (byte)0x49,
    (byte)0x14, (byte)0x1A, (byte)0x41, (byte)0x84,
    (byte)0x00, (byte)0x00
    }; // this format could be read from Smart Messaging Specification
    //SMS-3.0
    Sound sound;
    sound = new Sound(music, Sound.FORMAT_TONE);
    sound.init(music, Sound.FORMAT_TONE);
    sound.play(1);

    Good luck

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    8

    7650 doesn't even support Sound?

    I am using the Nokia Developer Suite for J2ME 1.1 and using the "Series 60 MIDP SDK for Symbian OS edition 1.0" emulator.

    I tried some code to test out sounds but it throws with the exception "Sound not supported"

    When I use the 3650 emulator (Nokia Series 60 MIDP Concept SDK Beta 0.2), the sound works perfectly fine.

    I also tried to use the real 7650 phone and 6100 (too bad I don't have an actual 3650 phone). 6100 works with the music and 7650 doesn't, just like the emulator.

    Anybody has any idea? Here's my code:
    // Initialization. soundata is pre-filled with valid byte array.
    try {
    mySound = new Sound(soundata, Sound.FORMAT_TONE);
    mySound.init(soundata, Sound.FORMAT_TONE);
    } catch (Exception ignored) {}

    // Playing the sound
    try {
    mySound.play(0);
    } catch (Exception err) {
    System.out.println("Error caught: " + err.toString());
    try {
    mySound.release();
    } catch (Exception ignored) {
    } finally {
    mySound = null;
    }
    }

    (sorry for the bad indentation. I am not familiar with HTML so I don't know how to properly indent the code in the post)

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    10

    Hi

    I really don't know why your code was not working ?
    But try my code. I have 2 mobiles : 7650 (series 60) and 6610(series 40). I tried to install my code and they all seemed to work properly with sound. I even played the "No limit" melody !!! But the simulator always seems to be wrong when playing sound. Don't believe in the simulator. I hate the simulator . Why don't we write new simulator (take us a long time) !!!!!

    Your code is good. Why didn't it work ? I really don't find out the reason now !!!

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    4

    tnx for your replies..

    luanhhoa...
    i tried that code already before.. something like that.. and also like what _ericlo_ did.. but it just won't play on my actual phone.. but it plays on 3650 units.

    it's really weird.. i haven't tried it yet on the emulator. i'm working on a pc without sound card, so can't help it

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    4

    follow up ...

    did you actually test it on your 7650?? somebody reported to me that someone made it to work but i tried it with 2 7650 but same results

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    10

    hi

    Yes, I did. It seemed to work properly and easily. I am not telling a lie !!! Maybe I found out some troubles when changing the location of variables declaration.
    When using LOCAL variables, maybe the sound will be mute due to variable destruction after function returns.
    You should use "music" , "sound" as GLOBAL variables. Thanks to that, you can hear the sound. Because the 2 variables will not be destroyed.
    The following code is appropriate :

    // declare as global variables
    byte music[] = {
    (byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x51,
    (byte)0x35, (byte)0xA5, (byte)0x91, (byte)0xA4,
    (byte)0x04, (byte)0x00, (byte)0x3F, (byte)0x1E,
    (byte)0x96, (byte)0x20, (byte)0xE3, (byte)0x12,
    (byte)0x45, (byte)0x28, (byte)0x30, (byte)0xC4,
    (byte)0x98, (byte)0x49, (byte)0x16, (byte)0x15,
    (byte)0x41, (byte)0x36, (byte)0x15, (byte)0x61,
    (byte)0x14, (byte)0x20, (byte)0xC2, (byte)0x12,
    (byte)0x45, (byte)0x06, (byte)0x90, (byte)0x61,
    (byte)0x05, (byte)0x58, (byte)0x59, (byte)0x86,
    (byte)0x0A, (byte)0x83, (byte)0x08, (byte)0x49,
    (byte)0x14, (byte)0x1A, (byte)0x41, (byte)0x84,
    (byte)0x00, (byte)0x00
    };
    Sound sound;


    // call within any functions
    sound = new Sound(music, Sound.FORMAT_TONE);
    sound.init(music, Sound.FORMAT_TONE);
    sound.play(1);

    Good luck to you !!!

  9. #9
    Registered User
    Join Date
    May 2003
    Posts
    4

    tnx.

    ok.. tnx.. will try.

  10. #10
    Registered User
    Join Date
    May 2003
    Posts
    8

    The wav works fine.

    The wav code works fine (at least) on the emulator. I will try and see if it works on the actual phone.

    I still can't get the ringtone one to work for some pretty strange reason. (Fascinating how I can get the wav work but not the simple ringtone....)

    Anyways, thanks for your help.

    Best regards,
    Eric

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    10
    I run both of them (wav & ringtone) at 7210 simulator.

    The method of wav is not work.

    It will stop at this line.
    "
    sound = new Sound(buffer, Sound.FORMAT_WAV);
    "
    The error message is Error: null.

    I do not understand, buffer.length is not null or zero.

    The other one, ringtone method is ok.

    But I do not know how to make the byte data.


    Someone know what's happen?

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    10
    The file "punch1.wav" should be in the directory "D:\WTK104\apps\racing\res" ("D:\WTK104\apps\racing" is the default directory of your MIDlet application).
    The number 3590 is the size of the file "punch1.wav".
    That's all. I think you should pay attention to 2 things above.

    InputStream tune;
    byte buffer[];
    Sound sound;
    tune = this.getClass().getResourceAsStream("/punch1.wav");
    buffer = new byte[3590]; // 3590 is the file size
    tune.read(buffer, 0, buffer.length);
    sound = new Sound(buffer, Sound.FORMAT_WAV);
    sound.init(buffer, Sound.FORMAT_WAV);
    sound.play(1);

    You could create ringtone data thanks to Smart Messaging Specification 3.0 (you could search this keyword by Google Engine or load it on Nokia Webpage). Maybe it is complicated but easy !!!

  13. #13
    Registered User
    Join Date
    Mar 2003
    Posts
    10

    Thanks a lot

    Thanks a lot, luanhhoa.

    This is my code:


    tune = this.getClass().getResourceAsStream("/kiki01.wav");
    buffer = new byte[16038]; // 16038 is the file size
    tune.read(buffer, 0, buffer.length);
    sound = new Sound(buffer, Sound.FORMAT_WAV);


    The wav file is in my .jar file, and it is at root directory( at jar file).

    I have test another error file name, like kiki.wav(of cource it is not exist) , the buffer.length is null(occur error : line 3).

    If I test by the right file name, the buffer.length is 16038, the same as the file length(occur error : line 4).

    I also have put the program in to real machine, still slience....

    Anyway, I have download the file that you tell me, maybe ringtone is more useful for me.

  14. #14
    Registered User
    Join Date
    May 2003
    Posts
    10
    You should declare some variables as global ones (not local).
    If they are local ones, maybe they are destroyed after the function returns.

    InputStream tune;
    byte buffer[];
    Sound sound;

    Initialize the variables such as (your code) :

    tune = this.getClass().getResourceAsStream("/kiki01.wav");
    buffer = new byte[16038]; // 16038 is the file size
    tune.read(buffer, 0, buffer.length);
    sound = new Sound(buffer, Sound.FORMAT_WAV);


    You forgot calling some instructions such as

    sound.init(buffer, Sound.FORMAT_WAV);
    sound.play(1);


    That's all. Hope to receive new information.

  15. #15
    Registered User
    Join Date
    Mar 2003
    Posts
    10

    It still not work

    luanhhoa,

    It is my code. I have check anything that you have told me.

    Althouth the way of wav still not work, but I am happy that I have learn how to play music by RingTone.

    In my code there is a sample by RingTone, thank for your help.

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

    public class Sample15 extends MIDlet implements CommandListener
    {
    private Display firstDisplay ;
    private Command PlayCommand;

    InputStream tune;
    byte buffer[];
    Sound sound;


    //--------------------------------------------------------------
    public Sample15()
    {
    try {
    firstDisplay = Display.getDisplay(this);
    Form r = new Form("Music");
    PlayCommand = new Command("play", Command.OK, 1) ;
    r.addCommand(PlayCommand);
    r.setCommandListener(this);
    firstDisplay.setCurrent(r);

    } catch (Exception e) {
    System.out.println("Error: " + e.getMessage()) ;
    }
    }
    //--------------------------------------------------------------
    public void startApp()
    {

    }

    //--------------------------------------------------------------
    public void pauseApp()
    { }
    public void destroyApp(boolean b)
    {
    }

    void exitRequested()
    {
    destroyApp(false);
    notifyDestroyed();
    }

    public void commandAction(Command c, Displayable s)
    {
    try {
    if (c == PlayCommand)
    {

    /*
    byte music[] = {
    (byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x51,
    (byte)0xD1, (byte)0x95, (byte)0xCD, (byte)0xD0,
    (byte)0x04, (byte)0x00, (byte)0x1D, (byte)0x20,
    (byte)0x61, (byte)0x05, (byte)0x50, (byte)0x54,
    (byte)0x85, (byte)0x90, (byte)0x4D, (byte)0x04,
    (byte)0xC8, (byte)0x45, (byte)0x04, (byte)0xD0,
    (byte)0x55, (byte)0x05, (byte)0x90, (byte)0x61,
    (byte)0x06, (byte)0x10, (byte)0x60, (byte)0x80,
    (byte)0x00, (byte)0x00
    }; // this format could be read from Smart Messaging Specification
    //SMS-3.0
    Sound sound;
    sound = new Sound(music, Sound.FORMAT_TONE);
    sound.init(music, Sound.FORMAT_TONE);
    sound.play(1);
    */

    tune = this.getClass().getResourceAsStream("/kiki01.wav");
    buffer = new byte[16038]; // 16038 is the file size
    tune.read(buffer, 0, buffer.length);
    sound = new Sound(buffer, Sound.FORMAT_WAV);
    sound.init(buffer, Sound.FORMAT_WAV);
    sound.play(1);

    }
    } catch (Exception e) {
    System.out.println("Error: " + e.getMessage()) ;

    }
    }

    }

Posting Permissions

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