# Titanium.Media.MusicPlayer

This object represents a music controller.

Availability
1.4.0
9.2.0

# 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

Availability
3.2.0
9.2.0
apiName :String

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

Availability
3.0.0
9.2.0
bubbleParent :Boolean

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

Availability
1.4.0
9.2.0
currentPlaybackTime :Number

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

Availability
1.4.0
9.2.0
nowPlaying :Titanium.Media.Item

An Item object representing the currently playing media item.


# repeatMode

Availability
1.4.0
9.2.0
repeatMode :Number

Repeat setting.


# shuffleMode

Availability
1.4.0
9.2.0
shuffleMode :Number

Shuffle setting.

# Methods

# addEventListener

Availability
1.4.0
9.2.0
addEventListener(name, callback) void

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

Availability
3.0.0
9.2.0
applyProperties(props) void

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

Availability
1.4.0
9.2.0
fireEvent(name[, event]) void

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

# pause

Availability
1.4.0
9.2.0
pause() void

Pauses playback of the current media item.

Returns

Type
void

# play

Availability
1.4.0
9.2.0
play() void

Begins playback of the current media item.

Returns

Type
void

# removeEventListener

Availability
1.4.0
9.2.0
removeEventListener(name, callback) void

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 addEventListener.

Returns

Type
void

# seekBackward

Availability
1.4.0
9.2.0
seekBackward() void

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

Availability
1.4.0
9.2.0
seekForward() void

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

Availability
1.4.0
9.2.0
setQueue(queue) void

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

Availability
1.4.0
9.2.0
skipToBeginning() void

Skips to the beginning of the currently playing media item.

Returns

Type
void

# skipToNext

Availability
1.4.0
9.2.0
skipToNext() void

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

Availability
1.4.0
9.2.0
skipToPrevious() void

Skips to the previous media item in the queue.

If there are no previous media items in the queue, ends playback.

Returns

Type
void

# stop

Availability
1.4.0
9.2.0
stop() void

Stops playback of the current media queue.

Returns

Type
void

# stopSeeking

Availability
1.4.0
9.2.0
stopSeeking() void

Ends a seek operation and returns to the previous playback state.

See also: seekForward and seekBackward.

Returns

Type
void

# Events

# playingchange

Availability
3.0.0
9.2.0

Fired when the currently playing media item changes.

See nowPlaying to identify the current media item.


# statechange

Availability
3.0.0
9.2.0

Fired when the music player's playback state changes.

See playbackState to identify the current playback state.