sinkuri256 / android-scripting

Automatically exported from code.google.com/p/android-scripting
0 stars 0 forks source link

Improved MediaPlayer support #494

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Implementation of a MediaPlayer interface.

(Originally issue 190)

Trial implementation in place

Unofficial versions:

http://www.mithril.com.au/android/sl4a_r3x.apk (latest code)
http://www.mithril.com.au/android/sl4a_r3a.apk (retrofit to R3)

Code in clone rjmatthews62-android-scripting MediaPlayerFacade.java

API description:
*!MediaPlayerFacade*
  * [#mediaIsPlaying mediaIsPlaying]
  * [#mediaPlay mediaPlay]
  * [#mediaPlayClose mediaPlayClose]
  * [#mediaPlayInfo mediaPlayInfo]
  * [#mediaPlayList mediaPlayList]
  * [#mediaPlayPause mediaPlayPause]
  * [#mediaPlaySeek mediaPlaySeek]
  * [#mediaPlaySetLooping mediaPlaySetLooping]
  * [#mediaPlayStart mediaPlayStart]
mediaIsPlaying(
 String tag[optional, default default]: string identifying resource)

Checks if media file is playing.

Returns:
  true if playing

mediaPlay(
 String url: url of media resource,
 String tag[optional, default default]: string identifying resource,
 Boolean play[optional, default true]: start playing immediately)

Open a media file

Returns:
  true if play successful

mediaPlayClose(
 String tag[optional, default default]: string identifying resource)

Close media file

Returns:
  true if successful

mediaPlayInfo(
 String tag[optional, default default]: string identifying resource)

Information on current media

Returns:
  Media Information

mediaPlayList()

Lists currently loaded media

Returns:
  List of Media Tags

mediaPlayPause(
 String tag[optional, default default]: string identifying resource)

pause playing media file

Returns:
  true if successful

mediaPlaySeek(
 Integer msec: Position in millseconds,
 String tag[optional, default default]: string identifying resource)

Seek To Position

Returns:
  New Position (in ms)

mediaPlaySetLooping(
 Boolean enabled[optional, default true],
 String tag[optional, default default]: string identifying resource)

Set Looping

Returns:
  True if successful

mediaPlayStart(
 String tag[optional, default default]: string identifying resource)

start playing media file

Returns:
  true if successful

-------------
How to use:
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 mediaPlayStart() 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" - tag for this module.
    * "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 mediaSetLooping 

You can use mediaPlayList to get a list of the loaded tags.
mediaIsPlaying will return true if the media is playing. (mediaPlayInfo) NB: In 
remote mode, a media file will continue playing after the script has finished 
unless an explicit "mediaPlayClose" event is called. 

Sample python scripts attached.

Original issue reported on code.google.com by rjmatthews62 on 27 Dec 2010 at 5:37

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by rjmatthews62 on 9 Jan 2011 at 12:40