Play Sound in midlet

javax.microedition.media package is introduced in MIDP2.0 profile. This package supports sound and upward compatibility with MultiMedia API.It has Manager, Player and Control as main objects.Different audio files, from various locations can be played on mobile.

Simple Media Playback
try
{
Player p = Manager.createPlayer("http://webserver/music.wav");
p.start();
}
catch (IOException ioe) { }
catch (MediaException me) { }

Playing Back from Media Stored in JAR
try
{
InputStream is = getClass().getResourceAsStream("music.wav");
Player p = Manager.createPlayer(is, "audio/X-wav");
p.start();
}
catch (IOException ioe) { }
catch (MediaException me) { }

3 comments:

  1. Pls tell a method to play media in GUI forms rather than individual midlets,since i'm using visual midlets to play media.

    ReplyDelete
  2. Does ne1 know how can i play sounds in j2me without ne delay?
    i mean if i write a function Play() it should play the sound instantly no matter what.. because the sound represents a collision. now collisions can happen rapidly.. ie before the sound for prev. collision ceases another collision may take place..

    I tried two things

    Play(){
    sound.start();
    }
    The problem in this is that if the sound is playing it wont restart it. it will just ignore it.

    Play(){
    sound.stop();
    sound.start();
    }
    The problem here is it decrease the game speed..

    ReplyDelete
  3. continually I visited your blog looking for some news about this, and thanks to your wonderful work all the time I find just I need to know.

    ReplyDelete

 

Design by Blogger Buster | Distributed by Blogging Tips