Scmad Chapter12


Published on

Chapter 12 - only for studies purposes.

Published in: Sports, Technology
  • Be the first to comment

  • Be the first to like this

Scmad Chapter12

  1. 1. By Marcel Caraciolo Chapter 12– MIDP Sound API SCMAD Certification 45mm 61mm
  2. 2. Agenda <ul><li>MIDP – Sound API </li></ul><ul><ul><li>Sound API </li></ul></ul><ul><ul><li>Manager </li></ul></ul><ul><ul><li>Player </li></ul></ul><ul><ul><li>Control </li></ul></ul><ul><ul><li>Controllable </li></ul></ul><ul><ul><li>PlayerListener </li></ul></ul><ul><ul><li>Controls </li></ul></ul>
  3. 3. MIDP Sound API <ul><li>MIDP defines a basic sound API. MMAPI (Mobile Media API) provides support to more sophisticated media devices, an its API extends MIDP’s. It will be descrived on the next chapter. </li></ul><ul><li>Devices must at least be able to generate monophonic tones. </li></ul><ul><li>Allows playing recorded media (independently of the encoding), tone generation and controls (e.g. volume). </li></ul><ul><li>Video is not supported. MMAPI is required for handling video. </li></ul><ul><li>Media files may be downloaded from the network or packaged on the JAR. </li></ul>
  4. 4. MIDP Sound API <ul><li>Minimum requirements: </li></ul><ul><ul><li>Tone generation </li></ul></ul><ul><ul><li>If recorded media is supported, PCM wav 8 bit, 8 KHZ format must be supported. Additional formats may be supported </li></ul></ul><ul><ul><li>MIDI may be supported </li></ul></ul><ul><li>Like network operations, media operations must also be executed on separate threads, because resource loading and infrastructure access may consume time. A resource execution (start method) is not blocking ONLY when all resources are already loaded. </li></ul><ul><li>Classes at package. </li></ul><ul><li>API is based on three main classes: Manager, Player and Control. </li></ul>
  5. 5. M Manager <ul><li>Factory to create Players, which execute media operations </li></ul><ul><li>All methods are static </li></ul><ul><li>Factory methods: Manager.createPlayer() </li></ul>
  6. 6. M Manager <ul><li>Players may be created from: </li></ul><ul><ul><li>A media locator: URL that defines origin and content type to be processed. There are three types of media locator: </li></ul></ul><ul><ul><ul><li>An URL referencing a resource to be executed (e.g. http://server/music.mid or rtp://host/type). The content type is part of the response header and the content is part of the response body. </li></ul></ul></ul><ul><ul><ul><li>A device to generate sound programmatically. (e.g. device://tone or device:// midi) . An “empty” player is created, and sound is created programmatically. </li></ul></ul></ul><ul><ul><ul><li>An URL accessing a media capture device (e.g. capture:// audio, capture:// video, capture://radio) </li></ul></ul></ul>
  7. 7. M Manager <ul><li>Players may be created from: </li></ul><ul><ul><li>An input stream: For instance, the stream can be from a JAR resource or from the network. The content type may be discovered from the content. </li></ul></ul><ul><ul><li>A DataSource (MMAPI only): Class that handles “fetching” data, decoupling data from its source and access protocol. </li></ul></ul>
  8. 8. M Manager: methods <ul><li>Players may be created from: </li></ul><ul><ul><li>playTone(note,duration,volume): Convenience method to play a tone. Plays a tone (integer from 0 to 127), during the specified time (milliseconds) using the specified volume ( 0 – 100). This method is non-blocking. </li></ul></ul><ul><ul><li>getSupportedContentTypes(protocol): Gets all supported content types for a specific protocol. If protocol is null, all supported content types are returned. Content types examples: </li></ul></ul><ul><ul><ul><li>audio/x-wav (PCM wav) </li></ul></ul></ul><ul><ul><ul><li>audio/midi (MIDI) </li></ul></ul></ul><ul><ul><ul><li>audio/x-tone-seq (Tone sequencing) </li></ul></ul></ul><ul><ul><ul><li>audio/mpeg (MP3) </li></ul></ul></ul><ul><ul><ul><li>video / mpeg (MPEG video) </li></ul></ul></ul>
  9. 9. M Manager: methods <ul><li>Players may be created from: </li></ul><ul><ul><li>getSupportedProtocols(content_type): Gets all protocols that can be used to access some content type (e.g. HTTP RTP). If null is informed, all protocols that can be used to access media are returned. </li></ul></ul><ul><ul><li>createPlayer(locator): Creates a player from a specified locator. </li></ul></ul><ul><ul><li>createPlayer(stream,type): Creates a player from stream, to execute the specified content type. If the type is null, the device will try to find out the content based on the stream’s content. </li></ul></ul><ul><ul><li>createPlayer(dataSource): Creates a player using dataSource. (Available only at MMAPI). </li></ul></ul>
  10. 10. MP Player Interface <ul><li>Controls media execution </li></ul><ul><li>Players are created using Manager’s factory methods, and the media executions begins calling start() method. If all data is already loaded, this call is not blocking. If not interrupted, the execution proceeds until the end of the media. </li></ul>
  11. 11. MP Player: Life cycle <ul><li>These are the player’s states: </li></ul><ul><ul><li>UNREALIZED: Right after its creation. No data is loaded, hence the following methods cannot be called: </li></ul></ul><ul><ul><ul><li>getContentType </li></ul></ul></ul><ul><ul><ul><li>setTimeBase/ getTimeBase </li></ul></ul></ul><ul><ul><ul><li>setMediaTime </li></ul></ul></ul><ul><ul><ul><li>getControl/ getControls </li></ul></ul></ul><ul><ul><li>REALIZED: Resources were fetched. Resource information is available and its content is possibly loaded. </li></ul></ul>
  12. 12. MP Player: Life cycle <ul><li>These are the player’s states (Continuing): </li></ul><ul><ul><li>PREFETCHED: Resources were loaded and are available to execution, probably already on the output buffers. When the execution is finished, the player returns to this state. </li></ul></ul><ul><ul><li>STARTED: Execution has started and has not finished. </li></ul></ul><ul><ul><li>CLOSED: Player is closed. Resources are freed and the player cannot be reused. </li></ul></ul>
  13. 13. MP Player: Life cycle <ul><li>When you create, start, wait for the media end and close a player , the life cycle is: </li></ul><ul><ul><li>UNREALIZED </li></ul></ul><ul><ul><li>REALIZED </li></ul></ul><ul><ul><li>PREFETCHED </li></ul></ul><ul><ul><li>STARTED </li></ul></ul><ul><ul><li>PREFETCHED </li></ul></ul><ul><ul><li>CLOSED </li></ul></ul>
  14. 14. MP Player: Methods <ul><li>getDuration(): Media duration. If it’s undefined (e.g. for live transmission streams) TIME_UNKNOWN is returned. </li></ul><ul><li>getContentType(): Media’s content type. </li></ul><ul><li>getState(): Current state ( UNREALIZED, REALIZED, PREFETCHED, STARTED or CLOSED). </li></ul><ul><li>realize(), prefetch() : Requests a start change. If it’s in a more advanced state (e.g. calling realize on PREFETCHED player) the call is ignored. These methods ARE blocking. </li></ul>
  15. 15. MP Player: Methods <ul><li>start(): Starts the media execution. If the player is not at PREFETCHED state, it will be prefetched before the execution starts. If it’s already executing, the call is ignored. If it’s called on a interrupted player (interrupted by stop or media end) the execution continues from the point where it stopped. It’s not blocking if the player is PREFETCHED. </li></ul><ul><li>stop(): Stops the execution at the current point. </li></ul><ul><li>deallocate(): Deallocate all player’s resources and it returns it to REALIZED state. Useful for devices that do not support mixing and the buffers must be freed if another resource is to be executed. </li></ul><ul><li>close(): Finishes a player and deallocates all the resources it consumes. </li></ul>
  16. 16. MP Player: Methods <ul><li>setMediaTime(now): Sets the execution on a specific time. If it’s a negative value, the media returns at the beginning. If it’s bigger than the resource duration, it goes to the end. Some resources may not support this operation (e.g. live transmissions). </li></ul><ul><li>setLoopCount(count): Repeats the media execution. By default it’s 1. Setting 0 is not valid and setting -1 repeats indefinitely. It cannot be called by a STARTED player. </li></ul><ul><li>addPlayerListener(playerlistener), removePlayerListener(playerListener): Adds/Removes an event listener, which is notified everytime a player changes its state. Event ordering is kept. </li></ul>
  17. 17. MP Control <ul><li>Marker interface (define no methods) </li></ul><ul><li>Controls the execution of processing of some media type. Examples: </li></ul><ul><ul><li>VolumeControl </li></ul></ul><ul><ul><li>FramePositioningControl </li></ul></ul><ul><ul><li>RecordControl </li></ul></ul><ul><li>A player may have several controls </li></ul>
  18. 18. MP Controllable <ul><li>Controllable: Object that “has controls”. Player implements Controllable. </li></ul><ul><li>Methods: </li></ul><ul><ul><li>getControls(): All controls supported by the object </li></ul></ul><ul><ul><li>getControl(controlType): Gets a control from its class name. If this control is not supported, null is returned. If the package name is omitted, it’s assumed that it belongs to package. </li></ul></ul>
  19. 19. MP Controllable <ul><li>PlayerListener: Receives player’s events notifications. Events are represented as strings so that new events may be added without changing the interface. </li></ul><ul><li>Event samples: </li></ul><ul><ul><li>STARTED </li></ul></ul><ul><ul><li>STOPPED </li></ul></ul><ul><ul><li>END_OF_MEDIA </li></ul></ul><ul><ul><li>VOLUME_CHANGED </li></ul></ul><ul><ul><li>ERROR </li></ul></ul><ul><ul><li>CLOSED </li></ul></ul><ul><li>Method: playerUpdate(player,event,eventData): An event has happened on this player with the parameter data. </li></ul>
  20. 20. MP Controls: VolumeControl <ul><li>Volume handling control. Volume value goes from 0 to 100 (inclusive). Mute may be set, which silents the media output but does not change the value returned by getLevel(). </li></ul><ul><li>Must be implemented by player that execute sample audio (e.g. wav), generated audio (e.g. MIDI or tones) and video with sound. </li></ul><ul><li>Methods: </li></ul><ul><ul><li>setMute(boolean) </li></ul></ul><ul><ul><li>isMuted() </li></ul></ul><ul><ul><li>setLevel(level) </li></ul></ul><ul><ul><li>getLevel() </li></ul></ul>
  21. 21. MP Controls: ToneControl <ul><li>Plays a monophonic media sequence. A player is obtained by Manager.TONE_DEVICE_LOCATOR locator. It’s an important control because this might be the only way to produce music on rudimentary devices. </li></ul><ul><li>Defines the setSequence( byte[]) method to set the media sequence. A sequence is defined by pairs that specify, on this order: </li></ul><ul><ul><li>Version </li></ul></ul><ul><ul><li>Tempo </li></ul></ul><ul><ul><li>Resolution </li></ul></ul><ul><ul><li>Blocks </li></ul></ul><ul><ul><li>Events </li></ul></ul>
  22. 22. To Tone Control: Sample Example
  23. 23. Example Codes <ul><li>Some examples and MIDlets samples are available for reference and studying at this link: </li></ul><ul><ul><li> mpc/chapter12.rar </li></ul></ul><ul><li>The source codes include: </li></ul><ul><ul><li>SoundPlayerMIDlet </li></ul></ul>
  24. 24. Future Work <ul><li>Next Chapter: </li></ul><ul><ul><li>MIDP – MMAPI </li></ul></ul>
  25. 25. References <ul><li>ALVES F. Eduardo. SCMAD Study Guide, </li></ul><ul><li>27/04/2008. </li></ul><ul><li>JAKL Andreas, Java Platform, Micro Edition Part </li></ul><ul><li>01 slides, 12/2007. </li></ul><ul><li>Sun Certification Mobile Application Developer </li></ul><ul><li>Website: []. </li></ul>