Showing posts with label j2me sound. Show all posts
Showing posts with label j2me sound. Show all posts

Playing local MP3

The method below creates player and play mp3 file.
public void run()
{
try
{
InputStream is = getClass().getResourceAsStream("/your.mp3");
player = Manager.createPlayer(is,"audio/mpeg");

player.realize();
// get volume control for player and set volume to max
vc = (VolumeControl) player.getControl("VolumeControl");
if(vc != null)
{
vc.setLevel(100);
}
player.prefetch();
player.start();
}
catch(Exception e)
{}
}

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) { }
 

Design by Blogger Buster | Distributed by Blogging Tips