Sampled sound means sound formats like WAV, where the data is a stream of sound samples that represent the sound every fraction of a second. MIDI, on the other hand, is a sequence of commands for a multi-instrument "virtual synthesizer."
To play a sound file accessible over HTTP, use:
Player player = Manager.createPlayer("http://something.com/somefile.wav"); player.start(); // implicitly calls realize() and prefetch()
To play a sound file that you have included in the MIDlet's JAR file, you
need to know its MIME type (for example, audio/x-wav
)
in advance. Then use:
InputStream is = getClass().getResourceAsStream("/somefile.wav"); Player player = Manager.createPlayer(is, "audio/x-wav"); player.start();
Note: In the Symbian platforms, when using a null
MIME
type parameter in player creation, the implementation may try to search a
suitable codec automatically. However, it is recommended to specify the MIME
type. In the Series 40 platform, content type is not auto-detected and when
creating a Player
from an InputStream, the MIME type
must be specified.
To play a sound file stored in an RMS "record store," use:
RecordStore rs = RecordStore.open("name"); byte[] data = rs.getRecord(id); ByteArrayInputStream is = new ByteArrayInputStream(data); Player player = Manager.createPlayer(is, "audio/x-wav"); player.start();
Note: When the device is set to the silent mode, it depends on the device whether the audio is still muted or audible when using the MMAPI. Some Series 40 devices have a separate setting for sound in the Games menu. Series 40 supports silent mode from 3rd Edition, FP1 onward.
Note: Mixing support was introduced in S60 3rd Edition. In older Symbian
Editions only one player was able to play at a time. With the MMAPI this is
expressed by a notification that mixing is not supported. The support can
be checked from the system property supports.mixing
,
which returns a boolean value true
if the mixing is supported.
When mixing is not supported and two players are started sequentially, the
last call for the start method will cause the first player to stop and the
second to start (not in the Series 40 platform).
Swap and Play
The Series 40 implementation supports "Swap and Play” functionality. For certain audio content, this works by allowing a MIDlet to prefetch more than one player, and pause one player while resuming another. In this way, several active players can exist at once. (True mixing is not yet supported.)
In the Series
40 implementation, calling start()
on one player does
not automatically stop a player that is already running.
Swap and Play is supported by some devices in 3rd edition (6280 and 7370 only) and fully from 3rd Edition, FP1 onwards.