In J2ME, the processing of sound requires the use of the mobile Media API (MMAPI), which is a MIDP1.0 optional package that is already contained in MIDP2.0. So if you use MIDP1.0, make sure your running environment is supported.
General mobile phone support for the sound file format for WAV, Mid and mpg. Please refer to your mobile phone documentation for details.
In the sound processing, there are many ways to deal with, here is the most commonly used situation, play the jar file in the WAV file.
The process of playing a sound file:
1, in a certain format to read sound files.
Playing a sound file in a jar file is typically a form of processing a sound file into a stream. Sample code:
InputStream is = This.getclass (). getResourceAsStream ("/autorun.wav");
Where the Autorun.wav file is located in the root directory of the jar file, if located in a different directory, you need to add the directory name, such as/res/autorun.wav.
2, will read the content passed to the player.
The stream information is passed to the player, and the player decodes it in a certain format, sample code:
Player player = Manager.createplayer (IS, "audio/x-wav");
The first parameter is the stream object, and the second parameter is the format of the sound file.
3, play sound.
Using the Player object's Start method, you can play the sound out, sample code:
Player.start ();
You can also set the number of sound playback times when you play a sound, which can be implemented using the Setloopcount method in the Player class, which you can use to refer to the API documentation.
The following is a test pass in the Nokia S60 simulator. The code is as follows:
Package sound;
Import javax.microedition.midlet.*;
Import javax.microedition.lcdui.*;
Import javax.microedition.media.*;
Import java.io.*;
public class Soundmidlet extends MIDlet {
Private player player = null;
/** Constructor * *
Public Soundmidlet () {
try{
InputStream is = This.getclass (). getResourceAsStream ("/autorun.wav");
Player = Manager.createplayer (IS, "audio/x-wav");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service