..


Sponsored Links

The handling of the Java ME

Article written by Antonio Coschignano
Page 1 of 4

The topic of multimedia in Java ME is very broad, as this is an essential feature of the devices for which this platform was designed. In this article I will try to introduce the management of audio, in particular the most basic of formats, from which he acquired the knowledge and basic techniques you can run into more complex topics. Then we go for the moment 'break' the wall of sound, we play our mobile phone.

Since MIDP 2.0 Java ME was introduced in a 'standard implementation for the management of audio. Previously, the audio was handled by the framework MMAPI (Mobile Media API) separately, ie not included in the standard platform. With MIDP 2.0, Sun has generated a series of libraries that fall within the profile MIDP natively, allowing also to devices that do not support MMAPI, a minimum of multimedia.
The libraries in question are the Audio Building Block (a subset of MMAPI) that support the management of tones and WAV format. Support for other audio files are device dependent. However, many of the things that we will see in this guide also apply to other types of the multimedia files.

The Manager class

The class javax.microedition.media.Manager represents the point of access to all functions related to playing media files. It provides a set of static methods that deal to create the player for playback of audio files or sequences of tones, and some details concerning control functions control media processing. In our case, controls that are made ​​are availables and ToneControl VolumeControl, that soon we will understand what it is.

The interface Player

The Player is an interface that dipone controllonao some methods that the life cycle (start () stop () etc. ..) playing a media file. This component is built by the Manager based on the file you want to reproduce.

The management of tones

To generate a tone tastira, just call the static method Playtone () of the Manager class:

 



 Manager.playTone (int note, int duration, int volume);

 
Let's see in detail the parameters passed into the method:

1) int notes
This value represents the frequency of the sound if you just want to play. The value ranging from 0 to 127, calculated using the formula:






 SEMITONE_CONST = 17.31234049066755 = 1 / (ln (2 ^ (1 / 12)))







 note = ln (freq/8.176) * SEMITONE_CONST



From here we get the frequency in Hertz. If you want to reproduce the note, in this case is 69 which means this formula is equivalent to 440 Hz

2) int duration
Indicates the duration of the tone in milliseconds

3) int volume
Simplify the volume of sound that goes from 0 to 100

Here is a simple piece of code that generates a tone:






 try {



  



 Manager.playTone (100, 100, 10);







 } Catch (MediaException ex) {



  



 ex.printStackTrace ();







 }



In the same category ...
E-Learning
Flash MX (Advanced) Flash MX (Advanced)
Become a designer of Web sites from 29 €.
Javascript (Course) Javascript (Course)
Complete guide to client-side scripting. From 39 €.
VB.NET (Course) VB.NET (Course)
Make Desktop Applications with Visual Basic.. From 49 €.
Sponsored Links