trouble with sound in J2ME

Discussion in 'Java' started by Jeff, Apr 1, 2006.

  1. Jeff

    Jeff Guest

    midp 2.0
    Java SE 5.0
    J2ME version 2.2

    Below is a piece of code I've having problems with playing on my handset
    (nokia 6630), it starts to play but the then stops... it doesn't finiesh the
    song it play for ca 1 second and then stops....

    This code below is my trouble code:
    try {
    System.out.println("Sound block starts");
    InputStream is = getClass().getResourceAsStream("/test.mid");
    Player player = Manager.createPlayer(is, "audio/midi");
    player.start();
    System.out.println("Sound block ends");
    }
    catch (IOException ioe) {
    }
    catch (MediaException me) {
    }

    Overview of threads in my midlet:
    main thread (threadA)- this thread is listening for responses from the
    handset for example....
    -> a new thread (threadB) and this is the thread the program is executed
    within
    It's in the threadB my trouble code is within....

    My midlet has 2 threads: threadA, threadB

    I created a simple test midlet where my trouble code was executed on main
    thread (the midlet had only one thread) and everything works fine...

    But why is it playing only 1 second in my trouble code?.... what must I do
    to fix this?.... I guess I maybe could have executed the music playing from
    the main thread but that again will give me lots of trouble as the sound
    should be syncronized with the actions in threadB

    Please give me some advice....

    Jeff
     
    Jeff, Apr 1, 2006
    #1
    1. Advertising

  2. Jeff wrote:

    > But why is it playing only 1 second in my trouble code?.... what must I do
    > to fix this?.... I guess I maybe could have executed the music playing
    > from the main thread but that again will give me lots of trouble as the
    > sound should be syncronized with the actions in threadB


    No, you should not start play from the main thread. Are you sure the sound
    file being executed is more than one second in length? Did your sample code
    execute the exact same sound file?

    --
    Darryl L. Pierce <>
    Homepage: http://mcpierce.multiply.com/
    "McVeigh's lawyer got him the death penalty, which, quite frankly,
    I could have done." - Jon Stewart
    *** Free account sponsored by SecureIX.com ***
    *** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
     
    Darryl L. Pierce, Apr 10, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. robin
    Replies:
    0
    Views:
    896
    robin
    Jul 20, 2003
  2. Boldra
    Replies:
    0
    Views:
    1,336
    Boldra
    Dec 3, 2003
  3. marko

    re-playing sound in J2ME

    marko, Dec 14, 2004, in forum: Java
    Replies:
    3
    Views:
    11,642
    Darryl L. Pierce
    Dec 15, 2004
  4. Luc The Perverse

    Sound Quality In Sound API

    Luc The Perverse, Oct 30, 2005, in forum: Java
    Replies:
    4
    Views:
    1,517
    Andrew Thompson
    Oct 31, 2005
  5. Replies:
    0
    Views:
    563
Loading...

Share This Page