Play audio using J2ME

What is the best way to play audio using J2ME Media libary? For example, should you use MMAPI or use the Midlet platformRequest (String s) method?

+5
source share
4 answers

The following code should work on 90-95% of phones supporting JSR-135. Ordering all the calls to various methods is key to making it portable. This sounds local to your JAR. Any streaming sound would be another problem in general :)

// loads the InputStream for the sound
InputStream inputStream = this.getClass().getResourceAsStream( musicFile );

// create the standard Player
musicPlayer = Manager.createPlayer( inputStream, musicEncoding );
musicPlayer.prefetch();

// add player listener to access sound events
musicPlayer.addPlayerListener( this );

if( loopMusic )
{    
    // use the loop count method for infinite looping
    musicPlayer.setLoopCount( -1 );
}

// The set occurs twice to prevent sound spikes at the very 
// beginning of the sound.
VolumeControl volumeControl = 
   (VolumeControl) musicPlayer.getControl( "VolumeControl" );
volumeControl.setLevel( curVolume );

// finally start the piece of music
musicPlayer.start();

// set the volume once more
volumeControl = (VolumeControl) musicPlayer.getControl( "VolumeControl" );
volumeControl.setLevel( curVolume );

// finally, delete the input stream to save on resources
inputStream.close();
inputStream = null;
+7
source

At best, what do you mean? Top quality? Best user experience? Do most of the standards comply?

( , ), - - J2ME, , MMAPI / . BlackBerry MMAPI , .

- MMAPI , - . , , , .

+3

, , , (- , URL- HTTP ).

, , , .

0

( Jar) , Shane . , , , .. , 2-3 .

-1
source

All Articles