×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    3

    Problem with PlaySound in JavaMe

    Hi everybody,
    I have a terrible problem with playing a sound in wav format, namely, this works, but the sound is repeated many times and make annoying "echo" effect. And that is not only in emulator but in the physical phone too.

    I think but that the problem is not in code itself but somewhat general. Can anybody get me some ideas how can I better optimise the sound in the midlet. Maybe the problems is that the graphics is too heavy or I have used not correct packages or so on ... ?

    Can anybody help me? Here the code, that I have used:

    // Configuration .. The code is writen in Eclipse environment, CLDC 1.1, MIDP 2.0

    // Call a function from a GameCanvas class
    if (soundOn) sound.play("Click.wav");

    /// I have created a special class for playing a sound
    import javax.microedition.media.*;
    import java.io.*;

    public class SoundEffects implements PlayerListener {

    private static Player player = null;

    PlayerListener pll;
    long mt=0;

    public SoundEffects()
    {

    }

    public void playerUpdate(Player player, String event, Object data)
    {
    if (event == PlayerListener.END_OF_MEDIA)
    {
    try
    {
    defplayer();
    }
    catch (MediaException me)
    {
    player = null;
    }
    }
    }

    void defplayer() throws MediaException
    {
    if (player != null)
    {
    if (player.getState() == Player.STARTED)
    {
    player.stop();
    }
    if (player.getState() == Player.PREFETCHED)
    {
    player.deallocate();
    }
    if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED )
    {
    player.close();
    }
    }
    player = null;
    }

    final synchronized void play (String filename)
    {
    try
    {
    defplayer();

    InputStream is = getClass().getResourceAsStream(filename);
    player = Manager.createPlayer(is, "audio/x-wav");
    player.addPlayerListener(this);
    player.realize();
    player.prefetch();
    player.start();

    mt = player.getMediaTime();
    player.setMediaTime(mt+1);

    }
    catch (Throwable t)
    {
    player = null;
    }
    }
    }
    Last edited by Dr.Sorg; 2010-04-28 at 06:25.

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Problem with PlaySound in JavaMe

    Hello Welcome to the forum nokia developer boards..

    Can you make sure that how many timed the method play (String filename) gets called?
    are you calling this in a loop?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    3

    Re: Problem with PlaySound in JavaMe

    Nee, no loop. Here for testing purposes I have restricted the codes into only one time calling and add the line "player.setLoopCount(-1)". No effect. Thanx for quicly response!

    Can it be, that the "wav" files must have some distinct parameters and my file are somewhat corrupt?
    Last edited by Dr.Sorg; 2010-04-28 at 13:36.

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: Problem with PlaySound in JavaMe

    check the wav file, play it directly on windows media player or put on the device and play it using native device player.

    thanks,
    ~Amitabh

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    3

    Re: Problem with PlaySound in JavaMe

    So I have some progress ... I separate the sound into its own thread, then after the calling of ... "player.start()" I have paused the thread with "Thread.sleep(200)". And it works. But this only in SonyEricsson emulators. In Nokia S40_6th_SDK it has still no effect for the short wav files (0.13 sec). The longer files work!

    Is there special methods to play a sound in Nokia phones? Can anybody explain what does that all means?


    ... So half an hour later ... I have tried to modify ma *wav file, namely decraese the rate (upt to 16 000 kHz) and this works! But of course sound is very annoying.

    So I modify my question! It is still active what these all means! Is there some restrictions with playing a sound from *wav file. Can anyone a link, where it is possible to fish all information, what is needed for writing effective sound on JavaME ?
    Last edited by Dr.Sorg; 2010-05-02 at 17:53.

Similar Threads

  1. STLPort namespace issue
    By yickhong in forum Open C/C++
    Replies: 0
    Last Post: 2009-04-09, 08:54
  2. SyncML link problem
    By samuel_ in forum Symbian
    Replies: 4
    Last Post: 2009-03-27, 08:02
  3. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  4. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  5. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

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