Nokia's phone does not seem to support sound playback very well.
Based on my experience of doing J2ME, this paper summarizes the methods of sound playback for Nokia's three models.
1. Nokia S40 (7210,3300) and S60 (3650,7650)
/*
These four models do not support MIDP2.0 media.
I only for the model I have done, the other models did not use the real machine test,
Do not know whether to support media in MIDP2.0
*/
Import com.nokia.mid.sound.*;
public class MyClass extends Canvas
{
......
Private sound ksound = null;
Private byte[] Datakill = {
(byte) 0x02, (Byte) 0x4a, (Byte) 0x3a, (byte) 0x40,
(byte) 0x04, (Byte) 0x00, (Byte) 0x0b, (byte) 0x28,
(byte) 0x83, (Byte) 0x28, (Byte) 0x28, (byte) 0xd2,
(byte) 0x28, (byte) 0x00
};
Private Fun ()
{
if (ksound! = null)
{
Ksound.stop ();
Ksound = null;
}
Ksound = new Sound (Datakill, sound.format_tone);
Ksound.setgain (255); Set volume
Ksound.play (1); Play, Cycle once
}
}//end MyClass.
/*
Note:
1. About Datakill data how to get.
First, you need to have a midi sound file;
Second, Nokia's nokia_developers_suite_for_j2me is needed.
Use the Audio Converter in this tool to convert MIDI files into byte data.
Then copy the resulting stuff into your code.
2. About WTK How to use the Nokia Lib.
In Nokia's Development tools catalogue
.. /nokia/devices/nokia_7210_midp_sdk_v1_0/lib or
.. /nokia/devices/series_60_midp_concept_sdk_beta_0_3_nokia_edition/lib
Found in Class.zip. Open, find Sound.class, unzip, should be able to get com/nokia/ui/sound/sound.class,
Then package the entire directory into a zip file and put it in the Lib of your project. On the line.
Or a direct point, the class.zip directly to the Lib can also be.
After compiling the package with WTK, open your jar file and put the COM folder containing the Sound.class
Delete, and finally the jar-size in the Jad according to the actual situation change.
Ok.
I do it anyway, trouble is very troublesome. But I really don't want to use the JBuilder.
I don't know if there's any easier way.
*/
2. Nokia 7610
/* This model supports midp2.0*/
Import javax.microedition.media.*;
public class MyClass extends Canvas ...
{
Private player player = null;
......
private void Fun ()
{
......
PlaySound ("Kill.mid"); The play function is called here
/* Place the Wtk2.1,kill.mid file in the Res directory */
}
protected void PlaySound (String source)
{
Create player
Try
{
if (player! = null)
{
Player.close ();
Player = null;
}
Player = Manager.createplayer (GetClass (). getResourceAsStream ("/" +source), "Audio/midi");
Player.addplayerlistener (this);
Player.setloopcount (1);
Player.realize ();
Player.start ();
}
catch (Exception PE)
{
Pe.printstacktrace ();
}
}
public void Playerupdate (final Player p, final String event, final Object EventData)
{
Queue a call to Updateevent in the user interface event queue
Display display = Display.getdisplay (Mycolorball);
Display.callserially (New Runnable () {
public void Run ()
{
Updateevent (P, event, EventData);
}
});
}
private void Updateevent (Player p, String event, Object EventData)
{
if (event = = End_of_media)
{
P.close ();
}
else if (event = = CLOSED)
{
p = null;
}
}
}//end MyClass.
===================================================
/*
Talk about another problem.
When switching out the program, the game sound still continues to play the solution.
*/
Add a function in the MyClass
void Stoptone ()
{
if (ksound! = null)
{
Ksound.stop ();
}
}
Add the following code to the Pauseapp () in MIDlet
public void Pauseapp ()
{
if (MyClass! = NULL//play sound interface exists
&& sound_s = = 1)//The sound switch is turned on
{
Myclass.stoptone ();
}
}
/* This is just a concept, two days to go on the real machine test * *