Sound in Pacman.

14 views
Skip to first unread message

Deg

unread,
Jan 27, 2010, 10:14:11 AM1/27/10
to Leeds ASchool
I have a very enthusiastic student who is still working on his Pacman
program 2 months after the course finished! Being enthusiastic he now
wants to add some sound to it. Can anyone recommend a nice easy way
that even someone like me would understand?

Deg.

leeds-aschool

unread,
Feb 1, 2010, 5:57:07 AM2/1/10
to Leeds ASchool
I found the following article related to multimedia but if you get the
student to do a search for "Java+ME+Sound". There are a number of hits
and provide code as well. For the after school club, the applications
were using an old Java ME library so he may need to update to the
later libraries but this could work.

Let me know how the student gets on.

Royce

How to Play sound in Java ME
From Forum Nokia Wiki [http://wiki.forum.nokia.com/index.php/
How_to_Play_sound_in_Java_M]


MMAPI (JSR 135) allows Java ME applications to easily access
MultiMedia functionalities, like playing and recording both video and
audio data. This article shows the steps required to play a sound,
from both local and network resources.
Source code

You need to import the following packages:

import java.io.*;
import javax.microedition.media.*;

The following code helps to play sound which is embedded in your jar
file

InputStream is = getClass().getResourceAsStream("sound.wav");
Player p = Manager.createPlayer(is, "audio/X-wav");
p.start();

The following code helps to play sound which is stored in a web server

Player p = Manager.createPlayer("http://server/sound.wav");
p.start();

You may also try other sound formats by minor changing ie; by changing
the mime type.

Also you have to keep in mind while giving the url in the second case,
use of special characters like '&' etc are not supported. In such case
you should follow the following method

HttpConnection hc = (HttpConnection) Connector.open(url);
InputStream in = hc.openInputStream();
Player p = Manager.createPlayer(is, "audio/X-wav");
p.start();

R. J. Neagle

unread,
Feb 1, 2010, 6:01:57 AM2/1/10
to Leeds ASchool
Found this in a forum. This explains why he is struggling to play
sounds!!!!

Is Java Sound available on J2ME / MIDP / Personal Java?
No. However, there is the Mobil Media API (MMAPI), which is developed
for J2ME. The "audio building block" of MMAPI is also part of MIDP
2.0. The design of MMAPI is similar to JMF. (Matthias)

We used JSME so it looks like you will need to get the MMAPI to be
able to play sounds. This can be downloaded from http://java.sun.com/products/mmapi/
and is an extension for J2ME used for the ASchool club.

Royce

Reply all
Reply to author
Forward
0 new messages