Skip to content

SL4A MediaPlayerFacade

michael edited this page Nov 9, 2015 · 6 revisions

This facade exposes basic mediaPlayer functionality.

Usage Notes:

mediaPlayerFacade maintains a list of media streams, identified by a user supplied tag. If the tag is null or blank, this tag defaults to "default"
Basic operation is: mediaPlayOpen("file:///sdcard/MP3/sample.mp3","mytag",true)
This will look for a media file at /sdcard/MP3/sample.mp3. Other urls should work. If the file exists and is playable, this will return a true otherwise it will return a false.

If play=true, then the media file will play immediately, otherwise it will wait for a mediaPlayerStart command.

When done with the resource, use mediaPlayClose

You can get information about the loaded media with mediaPlayInfo This returns a map with the following elements:

  • "tag" - user supplied tag identifying this mediaPlayer.
  • "loaded" - true if loaded, false if not. If false, no other elements are returned.
  • "duration" - length of the media in milliseconds.
  • "position" - current position of playback in milliseconds. Controlled by mediaPlaySeek
  • "isplaying" - shows whether media is playing. Controlled by mediaPlayPause and mediaPlayStart
  • "url" - the url used to open this media.
  • "looping" - whether media will loop. Controlled by mediaPlaySetLooping

You can use mediaPlayList to get a list of the loaded tags.
mediaIsPlaying will return true if the media is playing.

Events:
A playing media will throw a "media" event on completion.

NB: In remote mode, a media file will continue playing after the script has finished unless an explicit mediaPlayClose event is called.

mediaIsPlaying Checks if media file is playing.
tag (String) string identifying resource (default=default)
returns: (boolean) true if playing
mediaPlay Open a media file
url (String) url of media resource
tag (String) string identifying resource (default=default)
play (Boolean) start playing immediately (default=true)
returns: (boolean) true if play successful
mediaPlayClose Close media file
tag (String) string identifying resource (default=default)
returns: (boolean) true if successful
mediaPlayInfo Information on current media
tag (String) string identifying resource (default=default)
returns: (Map) Media Information
mediaPlayList Lists currently loaded media
returns: (Set) List of Media Tags
mediaPlayPause pause playing media file
tag (String) string identifying resource (default=default)
returns: (boolean) true if successful
mediaPlaySeek Seek To Position
msec (Integer) Position in millseconds
tag (String) string identifying resource (default=default)
returns: (int) New Position (in ms)
mediaPlaySetLooping Set Looping
enabled (Boolean) (default=true)
tag (String) string identifying resource (default=default)
returns: (boolean) True if successful
mediaPlayStart start playing media file
tag (String) string identifying resource (default=default)
returns: (boolean) true if successful
Clone this wiki locally