主要机型对应的音频格式以及震动功能列表
2005-12-11 15:51
405 查看
看到一片不错文章:http://jcodeworks.com/developersfxguide.html
整理了一个表格
原文如下:Developers reference guide on creating audio SFX, melodies and vibration on Nokia, Motorola, Sharp, Sagem and Sony mobile devices.Introduction
How many times have you thought your software works on a specific mobile device, because it works in the PC-emulator, only to find that once you try it on an actual device it crashes without any explanation why!
This guide will help software developers create 100% working FX on Nokia, Motorola, Sharp, Sagem and Sony mobile devices. This practical guide will include full-code for each device.
The most common FX required whilst developing mobile game software is the ability to:Play melodies
Play wave-audio
Vibrate
Although it is generally possible to create J2ME software that will work on all devices* it is impossible to create generic code that will activate these FX. *Apart from Nokia full screen mode, Motorola reverse soft-keys and Nokia 3650 alternative key layout.If the device you need is not listed below, please email me dan@jcodeworks.com and I will consider adding it.
FX Reference GuidePlease note: Although it might be possible to achieve melody, wave-audio and vibrate using different types of file-format I will only list one. The format described will (a) work!!! (b) use the least amount of processor time and (c) use the least amount of resources.Devices:Nokia 3650, 6600 and N-Gage
Nokia 7650
Motorola V525 and V600
Sagem myV65 and myV75
Sharp GX family *NEW*
Sony-Ericcson T6nn and Z600
Coming soon: (Email me if you need this NOW)Sony Ericsson S700, K700, K500, F500 family
Siemens S65, CX66
Nokia 6630
Motorola E680
Nokia 3650, 6600 and N-Gage
API: javax.microedition.media.* Restriction: Only play 1 FX at a time.
NOTE: You can add a listener that will inform you of Player events (e.g. Stopped - when Player finishes FX). To do this use: player.addPlayerListener(*class*). The specified *class* must implement PlayerListener.To catch the Listener events, use the following method inside *class*:public void playerUpdate(Player player, String event, Object obj) {
//player indicates which Player caused the event
//event informs you of event type
}Also: I have not tried PlayerListener on Nokia 6600 and N-Gage and so, cannot confirm that it works properly.- - -Melody: Available - plays .mid files (format zero)
The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them. It's the standard of all standards in the music creation world.
To LOAD a MIDI file:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("melody.mid"),"audio/midi");
player.realize();
player.prefetch(); //Remove this line for Nokia 6600 and N-Gage
} catch (Exception e0) {}
To PLAY the melody, ensure that you STOP all other players:try {
player.stop();
catch (Exception e1) {}… and then play your required melody with:try {
player.prefetch(); //Remove this line for Nokia 3650
player.setMediaTime(0); //Remove this for Nokia 6600 and N-Gage
player.setLoopCount(n); //n=number of times. -1=forever.
player.start();
catch (Exception e2) {}
Note: Playing a melody does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a melody resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
}- - -
Wave Audio: Available - plays .amr files (8 bit, rate can vary depending on quality required)
AMR files are a lot smaller than .WAV files. To create AMR files use the MIKSOFT Mobile AMR converter. Check it out at www.miksoft.8m.com
To LOAD a wave-audio:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("beep.amr"),"audio/amr");
player.realize();
player.prefetch();
} catch (Exception e0) {}
To PLAY the audio, ensure that you STOP all other players: try {
player.stop();
catch (Exception e1) {}
… and then play your required wave-audio with:try {
player.setMediaTime(0);
player.start();
catch (Exception e2) {}
Note: Calling the start() method does seem to take some time before calling back. So you will need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
}- - - Vibrate: Not available.
Nokia 7650
API: com.nokia.mid.sound.*
Restriction: Only play 1 FX at a time. NOTE: There does NOT seem to be any Sound listeners implemented on this device, so you will need to create your own means of determining if the Sound has finished using an elapsed time clock counter.- - -Melody: Not Available.- - -Wave Audio: Available – plays .WAV files (8bit, 8khz)WARNING: I have found that short wave-audio (e.g. under .7 of a second) do not play properly e.g. produce clicking noises or don't play at all.To LOAD a wave-audio:import com.Nokia.sound.*;
. . . .
byte[] bytes = readDataFromJar("beep.wav");
Sound sound;
if (bytes != null)
sound = new Sound(bytes, Sound.FORMAT_WAV);
. . . .
//utility method used by code above…
public byte[] readDataFromJar(String name) {
//get data from JAR resource
ByteArrayOutputStream bout;
InputStream in;
byte[] res = null;
try {
in = *canvas ref*.getClass().getResourceAsStream(name);
bout = new ByteArrayOutputStream();
for (int ret = in.read(); ret >= 0; ret = in.read())
bout.write(ret);
res = bout.toByteArray();
} catch (Exception e) {}
return res;
}
To PLAY the audio, ensure that you STOP all other wave-audio:if (sound != null)
sound.stop();… and then play your required wave-audio with:if (sound != null)
sound.play(n); //n = number of repeats, e.g. 1Note: Calling the play() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (sound != null) {
sound.stop();
sound = null;
}BUG NOTIFICATION: Some older 7650 firmware versions (version number unknown) crashes the application if you use the command 'setGain'. Once the application terminates, the device will display an error notification: jes-8e-javax.microedition.lcdui0@ 1...CMdaAudioPlayerU 2 (or similar - depending on firmware version). The application will crash even if you enclose the command with a try/catch exception handler.- - -Vibrate: Not available.
Motorola V525 and V600
API: Use javax.microedition.media.* for melody and wave-audio.
Use the MIDP2 display.vibrate command for vibration. Restriction: Only play 1 FX at a time.
NOTE: You can add a listener that will inform you of Player events (e.g. Stopped - when Player finishes FX). To do this use: player.addPlayerListener(*class*). The specified *class* must implement PlayerListener.To catch the Listener events, use the following method inside *class*: public void playerUpdate(Player player, String event, Object obj) {
//player indicates which Player caused the event
//event informs you of event type
}- - -Melody: Available - plays .mid files (format zero)
The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them. It's the standard of all standards in the music creation world.
To LOAD a MIDI file:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("melody.mid"),"audio/midi");
player.realize();
} catch (Exception e0) {}
To PLAY the melody, ensure that you STOP and DEALLOCATE all other players: try {
player.stop();
catch (Exception e1) {}
try {
player.deallocate();
catch (Exception e2) {}
… and then play your required melody with:try {
player.prefetch();
catch (Exception e3) {}
try {
player.setMediaTime(0);
catch (Exception e4) {}
player.setLoopCount(n); //n=number of times. -1=forever.
try {
player.start();
catch (Exception e5) {}
Note: Calling the start() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a melody resource:if (player != null) {
try {
player.close();
} catch (Exception e6) {}
player = null;
} - - -
Wave Audio: Available - plays .amr files (8 bit, rate can vary depending on quality required)
AMR files are a lot smaller than .WAV files. To create AMR files use the MIKSOFT Mobile AMR converter. Check it out at www.miksoft.8m.com
To LOAD a wave-audio:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("beep.amr"),"audio/amr");
player.realize();
player.prefetch();
} catch (Exception e0) {}
To PLAY the wave-audio, ensure that you STOP and DEALLOCATE all other players: try {
player.stop();
catch (Exception e1) {}
try {
player.deallocate();
catch (Exception e2) {}
… and then play your required wave-audio with:try {
player.prefetch();
catch (Exception e3) {}
try {
player.setMediaTime(0);
catch (Exception e4) {}
try {
player.start();
catch (Exception e5) {}
Note: Calling the start() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (player != null) {
try {
player.close();
} catch (Exception e6) {}
player = null;
} - - -Vibrate: Available.Use the MIDP2 built-in display class command:*display*.vibrate(duration); //duration is in milliseconds
Sagem myV65 and myV75
API: javax.microedition.media.*
Restriction: Only play 1 FX at a time.
NOTE: There does NOT seem to be any Player listeners implemented on this device, so you will need to create your own means of determining if the Player has finished using an elapsed time clock counter. - - -Melody: ***To be fully investigated***
Although it is possible to play MIDI files it is NOT 100% compatible. For example: I have not been able to play drum tracks. I need to investigate this in more depth and I will then write up my discoveries.- - -Wave Audio: Available – plays .WAV files (8bit, 8khz) WARNING: The Sagem is extremely fussy about wave-audio. You must only have 1 Player pre-fetched at any one time.To LOAD a wave-audio: import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("beep.wav"),"audio/x-wav");
player.realize();
} catch (Exception e0) {}
To PLAY the audio, ensure that you STOP and DEALLOCATE all other players:try {
player.stop();
catch (Exception e1) {}
try {
player.deallocate();
catch (Exception e2) {}… and then play your required wave-audio with:try {
player.prefetch();
catch (Exception e3) {}
try {
player.setMediaTime(0);
catch (Exception e4) {}
try {
player.start();
catch (Exception e5) {}
Note: Calling the stop(), deallocate(), prefetch() and start() methods does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (player != null) {
try {
player.close();
} catch (Exception e5) {}
player = null;
}As I mentioned earlier, the Sagem device is extremely fussy about wave-audio, and so I have tried to catch every possible problem with an exception. Remove the try/catches if you dare, but don't be too surprised if you start getting unexpected crashes!- - -Vibrate: Not available.Sharp GX family
Melody: Available - plays .mmf files
To play a melody, create a MIDI tune (format ZERO - max 4 channels) then use the Yamaha tool ATS-MA2-SMAF to convert it to .MMF format (get this from http://smaf-yamaha.com/)
Also: download the .PDF documentation files, as they are very useful.
To LOAD melody:static public void loadMelody() {
try {
byte[] data=readDataFromJar("/resources/tune.mmf"));
if (data!=null) {
mediaPlayer_tune=new MediaPlayer((byte[])null);
mediaPlayer_tune.setMediaData(data);
}
} catch (Exception ex) {}
}
To PLAY the melody, ensure that you STOP all other players:static public void playMelody(int idx) {
try {
loadMelody();
if (mediaPlayer_tune!=null)
//boolean states if melody repeats forever
mediaPlayer_tune.play(true);
} catch (Exception ex) {}
}- - -
Wave Audio: Available - plays .mmf files
I use .WAV files and convert them to .mmf files which I create using the Yamaha tool called "WAV-SMAF" (download this from http://smaf-yamaha.com/)
Also: download the .PDF documentation files, as they are very useful.To LOAD audio:MediaPlayer[] mediaPlayer;
String[] sounds={"sfx1.mmf","sfx2.mmf"};
int numberOfSounds=sounds.length;
…
static public void loadAudio() {
mediaPlayer=new MediaPlayer[numberOfSounds];
Media media=new Media();
byte[] data;
for (int i = 0; i < numberOfSounds; i++) {
try {
data=readDataFromJar("/resources/" + sounds[i]);
if (data!=null) {
mediaPlayer[i]=new MediaPlayer((byte[])null);
mediaPlayer[i].setMediaData(data);
mediaPlayer[i].setMediaPlayerListener(media);
Utility.hasSound = true;
}
} catch (Exception ex) {}
}static public byte[] readDataFromJar(String name) {
//get data from JAR resource
ByteArrayOutputStream bout;
InputStream in;
byte[] res = null;
try {
in = *canvas ref*.getClass().getResourceAsStream(name);
bout = new ByteArrayOutputStream();
for (int ret = in.read(); ret >= 0; ret = in.read())
bout.write(ret);
res = bout.toByteArray();
} catch (Exception e) {}
return res;
}
}
To PLAY the audio://idx is the sound FX that you want to play
mediaPlayer[idx].play();- - -Vibrate: To initialise:DeviceControl dc;
…
try {
dc = DeviceControl.getDefaultDeviceControl();
} catch (Exception ex) {}To START vibrate:if (dc!=null)
dc.setDeviceActive(DeviceControl.VIBRATION, true);To STOP vibrate:if (dc!=null)
dc.setDeviceActive(DeviceControl.VIBRATION, false); I use a timer thread to delay switching OFF the vibrate.
Sony-Ericsson T6nn and Z600
API: javax.microedition.media.* Restriction: Only play 1 FX at a time.NOTE: You can add a listener that will inform you of Player events (e.g. Stopped - when Player finishes FX). To do this use: player.addPlayerListener(*class*). The specified *class* must implement PlayerListener.To catch the Listener events, use the following method inside *class*:public void playerUpdate(Player player, String event, Object obj) {
//player indicates which Player caused the event
//event informs you of event type
}- - -Melody: Available - plays .mid files (format zero)
The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them. It's the standard of all standards in the music creation world.
To LOAD a MIDI file:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("melody.mid"),"audio/midi");
player.realize();
} catch (Exception e0) {}
To PLAY the melody, ensure that you STOP all other players:try {
if (player.getState() != Player.CLOSED)
player.stop();
catch (Exception e1) {}
… and then play your required melody with:try {
player.prefetch();
player.setLoopCount(n); //n=number of times. -1=forever.
player.start();
catch (Exception e2) {}
Note: Calling the prefetch() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a melody resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
} - - -Wave Audio: Available - plays .amr files (8 bit, rate can vary depending on quality required)
AMR files are a lot smaller than .WAV files. To create AMR files use the MIKSOFT Mobile AMR converter. Check it out at www.miksoft.8m.comNote: Many thanks to David Harries for revising the wave audio code.
To LOAD a wave-audio:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("beep.amr"),"audio/amr");
player.realize();
} catch (Exception e0) {}player.prefetch();
To PLAY the audio, ensure that you STOP all other players:try {
if (player.getState() != Player.PREFETCHED)
player.stop();
catch (Exception e1) {}
… and then play your required wave-audio with:try {
player.setLoopCount(1);
player.start();
catch (Exception e2) {}
Note: The prefetch() method does seem to take some time before calling back. So if you need to prefetch on the fly in a tight game loop you will need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
}- - -Vibrate: Available - using .imy file
To LOAD a Vibrate player:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer( *canvas ref*.getClass().getResourceAsStream("vibrate.imy"),"audio/iMelody");
player.realize();
player.prefetch();
} catch (Exception e0) {}
The VIBRATE.IMY is a text file with the following lines of code (to change the vibration delay alter the settings in the MELODY line):BEGIN:IMELODY
VERSION:1.2
FORMAT:CLASS1.0
BEAT:200
STYLE:S1
MELODY:vibeonr5vibeoff
END:IMELODYTo START the vibration, ensure that you STOP all other players:try {
if (player.getState() != Player.CLOSED)
player.stop();
catch (Exception e1) {}
… and then START the vibration with:try {
player.start();
catch (Exception e2) {}
Note: Calling the start() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a vibration resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
}
整理了一个表格
Device | Melody | Wave | Vibra | 1 FX at a time |
3650/6600/N-Gage | mid0 | amr | - | - |
7650 | - | wav | - | - |
Moto V525/V600 | mid0 | amr | Y | - |
Sagem myV65/myV75 | ? | wav | - | - |
Sharp GX familiy | mmf | mmf | Y | Y |
Sony-Ericsson T6xx/Z600 | mid0 | amr | Y | - |
How many times have you thought your software works on a specific mobile device, because it works in the PC-emulator, only to find that once you try it on an actual device it crashes without any explanation why!
This guide will help software developers create 100% working FX on Nokia, Motorola, Sharp, Sagem and Sony mobile devices. This practical guide will include full-code for each device.
The most common FX required whilst developing mobile game software is the ability to:Play melodies
Play wave-audio
Vibrate
Although it is generally possible to create J2ME software that will work on all devices* it is impossible to create generic code that will activate these FX. *Apart from Nokia full screen mode, Motorola reverse soft-keys and Nokia 3650 alternative key layout.If the device you need is not listed below, please email me dan@jcodeworks.com and I will consider adding it.
FX Reference GuidePlease note: Although it might be possible to achieve melody, wave-audio and vibrate using different types of file-format I will only list one. The format described will (a) work!!! (b) use the least amount of processor time and (c) use the least amount of resources.Devices:Nokia 3650, 6600 and N-Gage
Nokia 7650
Motorola V525 and V600
Sagem myV65 and myV75
Sharp GX family *NEW*
Sony-Ericcson T6nn and Z600
Coming soon: (Email me if you need this NOW)Sony Ericsson S700, K700, K500, F500 family
Siemens S65, CX66
Nokia 6630
Motorola E680
Nokia 3650, 6600 and N-Gage
API: javax.microedition.media.* Restriction: Only play 1 FX at a time.
NOTE: You can add a listener that will inform you of Player events (e.g. Stopped - when Player finishes FX). To do this use: player.addPlayerListener(*class*). The specified *class* must implement PlayerListener.To catch the Listener events, use the following method inside *class*:public void playerUpdate(Player player, String event, Object obj) {
//player indicates which Player caused the event
//event informs you of event type
}Also: I have not tried PlayerListener on Nokia 6600 and N-Gage and so, cannot confirm that it works properly.- - -Melody: Available - plays .mid files (format zero)
The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them. It's the standard of all standards in the music creation world.
To LOAD a MIDI file:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("melody.mid"),"audio/midi");
player.realize();
player.prefetch(); //Remove this line for Nokia 6600 and N-Gage
} catch (Exception e0) {}
To PLAY the melody, ensure that you STOP all other players:try {
player.stop();
catch (Exception e1) {}… and then play your required melody with:try {
player.prefetch(); //Remove this line for Nokia 3650
player.setMediaTime(0); //Remove this for Nokia 6600 and N-Gage
player.setLoopCount(n); //n=number of times. -1=forever.
player.start();
catch (Exception e2) {}
Note: Playing a melody does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a melody resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
}- - -
Wave Audio: Available - plays .amr files (8 bit, rate can vary depending on quality required)
AMR files are a lot smaller than .WAV files. To create AMR files use the MIKSOFT Mobile AMR converter. Check it out at www.miksoft.8m.com
To LOAD a wave-audio:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("beep.amr"),"audio/amr");
player.realize();
player.prefetch();
} catch (Exception e0) {}
To PLAY the audio, ensure that you STOP all other players: try {
player.stop();
catch (Exception e1) {}
… and then play your required wave-audio with:try {
player.setMediaTime(0);
player.start();
catch (Exception e2) {}
Note: Calling the start() method does seem to take some time before calling back. So you will need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
}- - - Vibrate: Not available.
Nokia 7650
API: com.nokia.mid.sound.*
Restriction: Only play 1 FX at a time. NOTE: There does NOT seem to be any Sound listeners implemented on this device, so you will need to create your own means of determining if the Sound has finished using an elapsed time clock counter.- - -Melody: Not Available.- - -Wave Audio: Available – plays .WAV files (8bit, 8khz)WARNING: I have found that short wave-audio (e.g. under .7 of a second) do not play properly e.g. produce clicking noises or don't play at all.To LOAD a wave-audio:import com.Nokia.sound.*;
. . . .
byte[] bytes = readDataFromJar("beep.wav");
Sound sound;
if (bytes != null)
sound = new Sound(bytes, Sound.FORMAT_WAV);
. . . .
//utility method used by code above…
public byte[] readDataFromJar(String name) {
//get data from JAR resource
ByteArrayOutputStream bout;
InputStream in;
byte[] res = null;
try {
in = *canvas ref*.getClass().getResourceAsStream(name);
bout = new ByteArrayOutputStream();
for (int ret = in.read(); ret >= 0; ret = in.read())
bout.write(ret);
res = bout.toByteArray();
} catch (Exception e) {}
return res;
}
To PLAY the audio, ensure that you STOP all other wave-audio:if (sound != null)
sound.stop();… and then play your required wave-audio with:if (sound != null)
sound.play(n); //n = number of repeats, e.g. 1Note: Calling the play() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (sound != null) {
sound.stop();
sound = null;
}BUG NOTIFICATION: Some older 7650 firmware versions (version number unknown) crashes the application if you use the command 'setGain'. Once the application terminates, the device will display an error notification: jes-8e-javax.microedition.lcdui0@ 1...CMdaAudioPlayerU 2 (or similar - depending on firmware version). The application will crash even if you enclose the command with a try/catch exception handler.- - -Vibrate: Not available.
Motorola V525 and V600
API: Use javax.microedition.media.* for melody and wave-audio.
Use the MIDP2 display.vibrate command for vibration. Restriction: Only play 1 FX at a time.
NOTE: You can add a listener that will inform you of Player events (e.g. Stopped - when Player finishes FX). To do this use: player.addPlayerListener(*class*). The specified *class* must implement PlayerListener.To catch the Listener events, use the following method inside *class*: public void playerUpdate(Player player, String event, Object obj) {
//player indicates which Player caused the event
//event informs you of event type
}- - -Melody: Available - plays .mid files (format zero)
The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them. It's the standard of all standards in the music creation world.
To LOAD a MIDI file:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("melody.mid"),"audio/midi");
player.realize();
} catch (Exception e0) {}
To PLAY the melody, ensure that you STOP and DEALLOCATE all other players: try {
player.stop();
catch (Exception e1) {}
try {
player.deallocate();
catch (Exception e2) {}
… and then play your required melody with:try {
player.prefetch();
catch (Exception e3) {}
try {
player.setMediaTime(0);
catch (Exception e4) {}
player.setLoopCount(n); //n=number of times. -1=forever.
try {
player.start();
catch (Exception e5) {}
Note: Calling the start() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a melody resource:if (player != null) {
try {
player.close();
} catch (Exception e6) {}
player = null;
} - - -
Wave Audio: Available - plays .amr files (8 bit, rate can vary depending on quality required)
AMR files are a lot smaller than .WAV files. To create AMR files use the MIKSOFT Mobile AMR converter. Check it out at www.miksoft.8m.com
To LOAD a wave-audio:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("beep.amr"),"audio/amr");
player.realize();
player.prefetch();
} catch (Exception e0) {}
To PLAY the wave-audio, ensure that you STOP and DEALLOCATE all other players: try {
player.stop();
catch (Exception e1) {}
try {
player.deallocate();
catch (Exception e2) {}
… and then play your required wave-audio with:try {
player.prefetch();
catch (Exception e3) {}
try {
player.setMediaTime(0);
catch (Exception e4) {}
try {
player.start();
catch (Exception e5) {}
Note: Calling the start() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (player != null) {
try {
player.close();
} catch (Exception e6) {}
player = null;
} - - -Vibrate: Available.Use the MIDP2 built-in display class command:*display*.vibrate(duration); //duration is in milliseconds
Sagem myV65 and myV75
API: javax.microedition.media.*
Restriction: Only play 1 FX at a time.
NOTE: There does NOT seem to be any Player listeners implemented on this device, so you will need to create your own means of determining if the Player has finished using an elapsed time clock counter. - - -Melody: ***To be fully investigated***
Although it is possible to play MIDI files it is NOT 100% compatible. For example: I have not been able to play drum tracks. I need to investigate this in more depth and I will then write up my discoveries.- - -Wave Audio: Available – plays .WAV files (8bit, 8khz) WARNING: The Sagem is extremely fussy about wave-audio. You must only have 1 Player pre-fetched at any one time.To LOAD a wave-audio: import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("beep.wav"),"audio/x-wav");
player.realize();
} catch (Exception e0) {}
To PLAY the audio, ensure that you STOP and DEALLOCATE all other players:try {
player.stop();
catch (Exception e1) {}
try {
player.deallocate();
catch (Exception e2) {}… and then play your required wave-audio with:try {
player.prefetch();
catch (Exception e3) {}
try {
player.setMediaTime(0);
catch (Exception e4) {}
try {
player.start();
catch (Exception e5) {}
Note: Calling the stop(), deallocate(), prefetch() and start() methods does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (player != null) {
try {
player.close();
} catch (Exception e5) {}
player = null;
}As I mentioned earlier, the Sagem device is extremely fussy about wave-audio, and so I have tried to catch every possible problem with an exception. Remove the try/catches if you dare, but don't be too surprised if you start getting unexpected crashes!- - -Vibrate: Not available.Sharp GX family
Melody: Available - plays .mmf files
To play a melody, create a MIDI tune (format ZERO - max 4 channels) then use the Yamaha tool ATS-MA2-SMAF to convert it to .MMF format (get this from http://smaf-yamaha.com/)
Also: download the .PDF documentation files, as they are very useful.
To LOAD melody:static public void loadMelody() {
try {
byte[] data=readDataFromJar("/resources/tune.mmf"));
if (data!=null) {
mediaPlayer_tune=new MediaPlayer((byte[])null);
mediaPlayer_tune.setMediaData(data);
}
} catch (Exception ex) {}
}
To PLAY the melody, ensure that you STOP all other players:static public void playMelody(int idx) {
try {
loadMelody();
if (mediaPlayer_tune!=null)
//boolean states if melody repeats forever
mediaPlayer_tune.play(true);
} catch (Exception ex) {}
}- - -
Wave Audio: Available - plays .mmf files
I use .WAV files and convert them to .mmf files which I create using the Yamaha tool called "WAV-SMAF" (download this from http://smaf-yamaha.com/)
Also: download the .PDF documentation files, as they are very useful.To LOAD audio:MediaPlayer[] mediaPlayer;
String[] sounds={"sfx1.mmf","sfx2.mmf"};
int numberOfSounds=sounds.length;
…
static public void loadAudio() {
mediaPlayer=new MediaPlayer[numberOfSounds];
Media media=new Media();
byte[] data;
for (int i = 0; i < numberOfSounds; i++) {
try {
data=readDataFromJar("/resources/" + sounds[i]);
if (data!=null) {
mediaPlayer[i]=new MediaPlayer((byte[])null);
mediaPlayer[i].setMediaData(data);
mediaPlayer[i].setMediaPlayerListener(media);
Utility.hasSound = true;
}
} catch (Exception ex) {}
}static public byte[] readDataFromJar(String name) {
//get data from JAR resource
ByteArrayOutputStream bout;
InputStream in;
byte[] res = null;
try {
in = *canvas ref*.getClass().getResourceAsStream(name);
bout = new ByteArrayOutputStream();
for (int ret = in.read(); ret >= 0; ret = in.read())
bout.write(ret);
res = bout.toByteArray();
} catch (Exception e) {}
return res;
}
}
To PLAY the audio://idx is the sound FX that you want to play
mediaPlayer[idx].play();- - -Vibrate: To initialise:DeviceControl dc;
…
try {
dc = DeviceControl.getDefaultDeviceControl();
} catch (Exception ex) {}To START vibrate:if (dc!=null)
dc.setDeviceActive(DeviceControl.VIBRATION, true);To STOP vibrate:if (dc!=null)
dc.setDeviceActive(DeviceControl.VIBRATION, false); I use a timer thread to delay switching OFF the vibrate.
Sony-Ericsson T6nn and Z600
API: javax.microedition.media.* Restriction: Only play 1 FX at a time.NOTE: You can add a listener that will inform you of Player events (e.g. Stopped - when Player finishes FX). To do this use: player.addPlayerListener(*class*). The specified *class* must implement PlayerListener.To catch the Listener events, use the following method inside *class*:public void playerUpdate(Player player, String event, Object obj) {
//player indicates which Player caused the event
//event informs you of event type
}- - -Melody: Available - plays .mid files (format zero)
The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them. It's the standard of all standards in the music creation world.
To LOAD a MIDI file:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("melody.mid"),"audio/midi");
player.realize();
} catch (Exception e0) {}
To PLAY the melody, ensure that you STOP all other players:try {
if (player.getState() != Player.CLOSED)
player.stop();
catch (Exception e1) {}
… and then play your required melody with:try {
player.prefetch();
player.setLoopCount(n); //n=number of times. -1=forever.
player.start();
catch (Exception e2) {}
Note: Calling the prefetch() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a melody resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
} - - -Wave Audio: Available - plays .amr files (8 bit, rate can vary depending on quality required)
AMR files are a lot smaller than .WAV files. To create AMR files use the MIKSOFT Mobile AMR converter. Check it out at www.miksoft.8m.comNote: Many thanks to David Harries for revising the wave audio code.
To LOAD a wave-audio:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer(*canvas ref*.getClass().getResourceAsStream("beep.amr"),"audio/amr");
player.realize();
} catch (Exception e0) {}player.prefetch();
To PLAY the audio, ensure that you STOP all other players:try {
if (player.getState() != Player.PREFETCHED)
player.stop();
catch (Exception e1) {}
… and then play your required wave-audio with:try {
player.setLoopCount(1);
player.start();
catch (Exception e2) {}
Note: The prefetch() method does seem to take some time before calling back. So if you need to prefetch on the fly in a tight game loop you will need to place it in a separate thread to the main game code.
To clean-up a wave-audio resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
}- - -Vibrate: Available - using .imy file
To LOAD a Vibrate player:import javax.microedition.media.*;
. . . .
Player player;
try {
player = Manager.createPlayer( *canvas ref*.getClass().getResourceAsStream("vibrate.imy"),"audio/iMelody");
player.realize();
player.prefetch();
} catch (Exception e0) {}
The VIBRATE.IMY is a text file with the following lines of code (to change the vibration delay alter the settings in the MELODY line):BEGIN:IMELODY
VERSION:1.2
FORMAT:CLASS1.0
BEAT:200
STYLE:S1
MELODY:vibeonr5vibeoff
END:IMELODYTo START the vibration, ensure that you STOP all other players:try {
if (player.getState() != Player.CLOSED)
player.stop();
catch (Exception e1) {}
… and then START the vibration with:try {
player.start();
catch (Exception e2) {}
Note: Calling the start() method does NOT seem to cause any serious delays. So you will NOT need to place it in a separate thread to the main game code.
To clean-up a vibration resource:if (player != null) {
try {
player.close();
} catch (Exception e3) {}
player = null;
}
相关文章推荐
- 在MFC中:静态文本类;按纽类;编辑框类;滚动条类;列表框类;组合框类等所对应的类名以及其功能
- 悲观锁和相比synchronized,ReentrantLock增加了一些高级功能,主要有以下3项:等待可 中断、可实现公平锁,以及锁可以绑定多个条件
- Oracle导入导出功能对应用户授权指令列表
- WAV格式音频文件头文件格式以及C++读取
- UDP的主要特点、首部格式及功能
- iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等
- 用jquery实现隐藏列表表单的显示关闭切换以及Ajax方式修改提交对应的那一行的修改内容。
- 实现app上对csdn的文章列表上拉刷新下拉加载以及加入缓存文章列表的功能 (制作csdn app 四)
- 摇一摇震动或播放音频案例以及分析详情
- 查看python 3中的内置函数列表,以及函数功能描述
- 常见Android屏幕分辨率以及对应机型
- 16、jsp的内置对象、功能以及主要方法
- Android /Java DecimalFormat(十进格式)的主要功能和使用方法
- Android开发系列(二十一):Spinner的功能和用法以及实现列表选择框
- 常用的linux系统文件夹名称以及对应的功能
- Spring框架分为哪七大模块以及各模块的主要功能作用
- 【C#版本详情回顾】C#2.0主要功能列表
- XAPO中LockForProcess 音频格式设置以及数据处理后的音频格式
- 〔转载〕专用格式对应专门软件列表
- ERP 之 本地列表与在线列表添加 关系 对应及删除功能