×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    77

    problem in playing wav file

    Hi all,
    i'm using nokia UI API Sound class to play simple wav file. when i try to run its giving exception as follows.

    Nokia Series 60 MIDP SDK Beta 0.1: java.lang.IllegalStateException
    Nokia Series 60 MIDP SDK Beta 0.1: at com.nokia.mid.sound.Sound.play(+54)
    Nokia Series 60 MIDP SDK Beta 0.1: at Player.playSound(+134)
    Nokia Series 60 MIDP SDK Beta 0.1: at Player.run(+16)


    here i am pasting my program. Plz help me in solving my problem. Plz help me.

    import java.lang.*;
    import java.io.*;
    import com.nokia.mid.sound.*;
    import javax.microedition.io.*;

    public class Player extends Thread implements SoundListener
    {
    private Sound soundWav = null;
    private String sMethod;
    private InputStream is=null;
    private Thread t = null;
    byte [] b;

    public Player(String method){
    sMethod=method;
    }

    public void run()
    {
    if(sMethod.equals("playSound"))
    {
    playSound();
    }

    }


    public void playSound()
    {
    try
    {
    HttpConnection c = (HttpConnection)Connector.open("http://203.196.161.72/Camera1a_2_8kHz.wav");
    is = c.openInputStream();
    b = new byte [(int)c.getLength()];
    is.read(b);
    System.out.println("array len is :"+b.length);
    soundWav = new Sound(b, Sound.FORMAT_WAV);
    System.out.println("after instance");
    soundWav.init(b, Sound.FORMAT_WAV);
    System.out.println("after initialization");
    soundWav.setSoundListener(this);
    System.out.println("after setlistener");
    soundWav.play(3);

    }
    catch (Exception e)
    {
    System.out.println("Exception");
    e.printStackTrace();
    }
    finally
    {
    try
    {
    if(is!= null)
    {
    is.close();
    }
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    }

    }

    public void soundStateChanged(Sound sound, int event)
    {

    System.out.println("in soundStateChanged");

    if (event == Sound.SOUND_PLAYING)
    {
    System.out.println("SoundWav begin playing");
    }else if (event == Sound.SOUND_STOPPED)
    {
    System.out.println("SoundWav end playing");
    }else if(event == Sound.SOUND_UNINITIALIZED)
    System.out.println("uninitialized");


    }
    }

    thanks in advance,

    Sridhar Reddy

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    21

    Re: problem in playing wav file

    Hi dear
    Perhaps problem owing to your wav file so please try another wav file .

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    Russia, Saint-Petersburg
    Posts
    40

    Re: problem in playing wav file

    a few years ago I wrote a universal sound player to use it in games for different devices, take a look at it may be it will help you
    http://igormaznitsa.com/projects/jcp/SoundManager.java
    A lot of useful things for a mobile developer on http://www.igormaznitsa.com

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: problem in playing wav file

    Quote Originally Posted by sridhar_ratna View Post
    Code:
        HttpConnection c = (HttpConnection)Connector.open("http://203.196.161.72/Camera1a_2_8kHz.wav");
        is = c.openInputStream();
        b = new byte [(int)c.getLength()];
        is.read(b);
    What device are you using?

    Your problem may be your use of InputStream.read(byte[]). This method does not always read the number of bytes you expect. You need to check the return value to see the number of bytes actually read. For example:

    Code:
    byte[] b = new byte [(int)c.getLength()];
    int soFar = 0;
    while (soFar < b.length) {
        soFar += in.read(b, soFar, b.length - soFar);
    }
    Cheers,
    Graham.

Posting Permissions

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