×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    7

    problem with playing sound

    I want to play a existed sound file (*.wav) which I have already put it into res folder. The problem is that the piece of code works properly in simulator (Sun java WTK 2.5.2 for CLDC). Then I created package and installed the app into my N97, it doesn't work at all. No error message, just give no response.

    Advanced thx for any help.

    Code:
    import java.io.InputStream;
    
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    
    public class PlayMusic {
    	public InputStream is;
    	public Player player;
    
    	public PlayMusic() {
    		try{
    	        is = getClass().getResourceAsStream("/q.wav");
    	        player = Manager.createPlayer(is, "audio/x-wav");
    	        
    		}catch (Exception e) {
                e.printStackTrace();
            }
        }
    	
    	public void sound(){
    		try {
    		    player.realize();
    		    player.prefetch();
    		    player.start();
    		} catch (MediaException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    	
    }
    This is MIDlet that invokes the code above
    Code:
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    
    public class test extends MIDlet {
    
             public test(){
            	
             }
    
    		protected void destroyApp(boolean arg0)
    				throws MIDletStateChangeException {
    			// TODO Auto-generated method stub
    			
    		}
    
    		protected void pauseApp() {
    			// TODO Auto-generated method stub
    			
    		}
    
    		protected void startApp() throws MIDletStateChangeException {
    			// TODO Auto-generated method stub
                  PlayMusic pm=new PlayMusic();
                    pm.sound();
    			
    				// TODO Auto-generated catch block
    				
    			}
    
    		}

  2. #2
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: problem with playing sound

    HI, elfen

    You develop your first MIDlet. You run it in the emulator. Finally, you get it working perfectly. Eagerly, you install it on your phone... you run it... and it fails miserably.

    This is the the article for you : Why doesn't my MIDlet run

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

    Re: problem with playing sound

    Quote Originally Posted by elfen_lied View Post
    Code:
    public PlayMusic() {
        try{
            is = getClass().getResourceAsStream("/q.wav");
            player = Manager.createPlayer(is, "audio/x-wav");
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
    	
    public void sound(){
        try {
            player.realize();
            player.prefetch();
            player.start();
        } catch (MediaException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    In these two methods, you are catching exceptions and doing nothing useful with them. There might be exceptions thrown, and they might be telling you useful information about your problem. Find out if any exceptions are being thrown.

    Do any other Java applications play sound? Check that "Warning Sounds" are switched on in the current ring-tone profile (and that it isn't silent!).

    WAV files should be 8kHz, mono, 8 bits per sample.

    Graham.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    7

    Re: problem with playing sound

    thanks 4 your reply, rahulvala. But i dont think it's the problem of packaging or installation. I have also wrote another midlet, a recorder using the same packaging tool(sun WTK 2.5.2) and it works fine on my N97. For this player, what annoys me is not that the midlet doesnt run. The problem is, the midlet can not play the audio file packaged in the jar file!! I spent the whole afternoon but still can not find out how to get the audio file played by my midlet

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    7

    Re: problem with playing sound

    Quote Originally Posted by grahamhughes View Post
    In these two methods, you are catching exceptions and doing nothing useful with them. There might be exceptions thrown, and they might be telling you useful information about your problem. Find out if any exceptions are being thrown.

    Do any other Java applications play sound? Check that "Warning Sounds" are switched on in the current ring-tone profile (and that it isn't silent!).

    WAV files should be 8kHz, mono, 8 bits per sample.

    Graham.
    Thanks Graham. I just transferred my audio file into 8kHz and 8 bits per sample and added System.out.println(e) for exception catching. But no exceptions were printed out when I ran the midlet on my N97.

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

    Re: problem with playing sound

    Quote Originally Posted by grahamhughes View Post
    Check that "Warning Sounds" are switched on in the current ring-tone profile (and that it isn't silent!).
    Did you check this?

    Quote Originally Posted by elfen_lied View Post
    But no exceptions were printed out when I ran the midlet on my N97.
    Where are you looking?

    Graham.

  7. #7
    Registered User
    Join Date
    Sep 2010
    Posts
    7

    Re: problem with playing sound

    Quote Originally Posted by grahamhughes View Post
    Did you check this?



    Where are you looking?

    Graham.
    Oh my god it's really embarrassing to reply you. But I need to give a great thank to you. Yes, the phone is in silent mode!! Next time i will learn to be more careful before i post such a primary question.

    Thanks to everyone helped me in this post.

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

    Re: problem with playing sound

    Oh, don't worry, you are not the first person to fall into this trap!

    Good luck with your project!

    Graham.

Similar Threads

  1. Problem playing tones after playing a sound file
    By mattbrenner in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2010-08-18, 05:35
  2. Problem playing sound on N70
    By smallbug005 in forum Mobile Java Games
    Replies: 3
    Last Post: 2009-07-17, 05:50
  3. Playing Sound jsr 135 problem need help :)
    By singh.jagatjit in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2007-06-21, 09:12
  4. Problem on playing sound in emulator
    By mhahn0106 in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2004-01-12, 06:00
  5. strange problem playing Sound on 7650
    By Poldipold in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2003-07-11, 13:12

Posting Permissions

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