# Titanium.Media.MusicPlayer
This object represents a music controller.
# Overview
A MusicPlayer
lets you manage and playback a queue of media Titanium.Media.Item objects.
To retrieve an instance of a MusicPlayer object, use either the Titanium.Media.appMusicPlayer or the Titanium.Media.systemMusicPlayer property.
Use the Titanium.Media module's Titanium.Media.openMusicLibrary and Titanium.Media.queryMusicLibrary methods to access the media items in the device's media library.
# Properties
# apiName READONLY
The name of the API that this proxy corresponds to.
The value of this property is the fully qualified name of the API. For example, Titanium.UI.Button
returns Ti.UI.Button
.
# bubbleParent
Indicates if the proxy will bubble an event to its parent.
Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.
Default: true
# currentPlaybackTime
Current point in song playback, in seconds.
This property is read/write, so you can update the music player's current position by setting this property.
# nowPlaying READONLY
An Item
object representing the currently playing media item.
# playbackState READONLY
Playback state.
# shuffleMode
Shuffle setting.
# Methods
# addEventListener
Adds the specified callback as an event listener for the named event.
Parameters
Name | Type | Description |
---|---|---|
name | String | Name of the event. |
callback | Callback<Titanium.Event> | Callback function to invoke when the event is fired. |
Returns
- Type
- void
# applyProperties
Applies the properties to the proxy.
Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.
Parameters
Name | Type | Description |
---|---|---|
props | Dictionary | A dictionary of properties to apply. |
Returns
- Type
- void
# fireEvent
Fires a synthesized event to any registered listeners.
Parameters
Name | Type | Description |
---|---|---|
name | String | Name of the event. |
event | Dictionary | A dictionary of keys and values to add to the Titanium.Event object sent to the listeners. |
Returns
- Type
- void
# removeEventListener
Removes the specified callback as an event listener for the named event.
Multiple listeners can be registered for the same event, so the
callback
parameter is used to determine which listener to remove.
When adding a listener, you must save a reference to the callback function in order to remove the listener later:
var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);
To remove the listener, pass in a reference to the callback function:
window.removeEventListener('click', listener);
Parameters
Name | Type | Description |
---|---|---|
name | String | Name of the event. |
callback | Callback<Titanium.Event> | Callback function to remove. Must be the same function passed to |
Returns
- Type
- void
# seekBackward
Begins seeking backward in the currently playing media.
Seeking speed increases as seeking continues.
Call stopSeeking to return to normal play.
Returns
- Type
- void
# seekForward
Begins seeking forward in the currently playing media item.
While seeking forward audio plays faster than usual. The speed increases as seeking continues.
Call stopSeeking to return to normal play.
Returns
- Type
- void
# setQueue
Sets the media queue.
Sets the media queue to a single media item or a list of items.
Starting in Titanium 6.1.0 you can also pass a String that identifies the Media item. This string has to be the persistentID property that identifies a media item uniquely.
Parameters
Name | Type | Description |
---|---|---|
queue | Titanium.Media.Item | Array<Titanium.Media.Item> | String | One or more media items. |
Returns
- Type
- void
# skipToBeginning
Skips to the beginning of the currently playing media item.
Returns
- Type
- void
# skipToNext
Skips to the next media item in the queue.
If there are no more media items in the queue, ends playback.
Returns
- Type
- void
# skipToPrevious
Skips to the previous media item in the queue.
If there are no previous media items in the queue, ends playback.
Returns
- Type
- void
# stopSeeking
Ends a seek operation and returns to the previous playback state.
See also: seekForward and seekBackward.
Returns
- Type
- void
# Events
# playingchange
Fired when the currently playing media item changes.
See nowPlaying to identify the current media item.
# statechange
Fired when the music player's playback state changes.
See playbackState to identify the current playback state.