Titanium.Media.Sound
> Titanium.Media.Sound

An object for playing basic audio resources.

The Sound object loads the entire media resource in memory before playing. If you need to support streaming, use the AudioPlayer API.

You can control how the sound interacts with other system sounds by setting Titanium.Media.audioSessionMode.

Use the Titanium.Media.createSound method to create a Sound object. You can play audio in any format supported by the target platform(s), as described in the following documents:

Examples

Simple Example

Simple example of playing a WAVE file from the Resources directory.

var player = Ti.Media.createSound({url:"sound.wav"});
player.play();
  • 0.8
  • 0.8
  • 0.8
Defined By

Properties

Titanium.Media.Sound
AUDIO_TYPE_ALARM : Numberreadonly

Used to identify the volume of audio streams for alarms.

Used to identify the volume of audio streams for alarms.

  • 6.2.0
Titanium.Media.Sound
AUDIO_TYPE_MEDIA : Numberreadonly

Used to identify the volume of audio streams for media playback.

Used to identify the volume of audio streams for media playback.

  • 6.2.0
Titanium.Media.Sound
AUDIO_TYPE_NOTIFICATION : Numberreadonly

Used to identify the volume of audio streams for notifications.

Used to identify the volume of audio streams for notifications.

  • 6.2.0
Titanium.Media.Sound
AUDIO_TYPE_RING : Numberreadonly

Used to identify the volume of audio streams for the phone ring.

Used to identify the volume of audio streams for the phone ring.

  • 6.2.0
Titanium.Media.Sound
AUDIO_TYPE_SIGNALLING : Numberreadonly

Used to identify the volume of audio streams for DTMF tones or beeps.

Used to identify the volume of audio streams for DTMF tones or beeps.

  • 6.2.0
Titanium.Media.Sound
AUDIO_TYPE_VOICE : Numberreadonly

Used to identify the volume of audio streams for voice calls.

Used to identify the volume of audio streams for voice calls.

  • 6.2.0
Titanium.Media.Sound
STATE_BUFFERING : Numberreadonly

Audio data is being buffered from the network.

Audio data is being buffered from the network.

  • 3.2.0
Titanium.Media.Sound
STATE_INITIALIZED : Numberreadonly

Audio playback is being initialized.

Audio playback is being initialized.

  • 3.2.0
Titanium.Media.Sound
STATE_PAUSED : Numberreadonly

Playback is paused.

Playback is paused.

  • 3.2.0
Titanium.Media.Sound
STATE_PLAYING : Numberreadonly

Audio playback is active.

Audio playback is active.

  • 3.2.0
Titanium.Media.Sound
STATE_STARTING : Numberreadonly

Audio playback is starting.

Audio playback is starting.

  • 3.2.0
Titanium.Media.Sound
STATE_STOPPED : Numberreadonly

Audio playback is stopped.

Audio playback is stopped.

  • 3.2.0
Titanium.Media.Sound
STATE_STOPPING : Numberreadonly

Audio playback is stopping.

Audio playback is stopping.

  • 3.2.0
Titanium.Media.Sound
STATE_WAITING_FOR_DATA : Numberreadonly

Player is waiting for audio data from the network.

Player is waiting for audio data from the network.

  • 3.2.0
Titanium.Media.Sound
STATE_WAITING_FOR_QUEUE : Numberreadonly

Player is waiting for audio data to fill the queue.

Player is waiting for audio data to fill the queue.

  • 3.2.0
Titanium.Media.Sound
: BooleanCreation-Only
Determines whether the audio should continue playing even when its activity is paused. ...

Determines whether the audio should continue playing even when its activity is paused.

Default: false

  • 1.3.0
apiName : Stringreadonly

The name of the API that this proxy corresponds to.

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, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Titanium.Media.Sound
: Number
Changes the audio-stream-type. ...

Changes the audio-stream-type.

This API can be assigned the following constants:

Default: Titanium.Media.AudioPlayer.AUDIO_TYPE_MEDIA

  • 6.2.0
Indicates if the proxy will bubble an event to its parent. ...

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

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.Media.Sound
duration : Numberreadonly

Duration of the audio resource.

Duration of the audio resource.

On iOS, playback time is reported in seconds.

On Android, time is reported in milliseconds.

Android note: Starting from Titanium 3.2.0, the remote audio plays asynchronously. The duration can only be fetched after the audio is initialized (refer to STATE_INITIALIZED).

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Titanium.Media.Sound
: Boolean
Determines whether the audio should loop upon completion. ...

Determines whether the audio should loop upon completion.

Default: false

Titanium.Media.Sound
paused : Boolean

Indicates if the audio is paused.

Indicates if the audio is paused.

On iOS, this property is read-write, and you can pause and resume playback by setting this property to true or false.

On Android, this property is read-only. For portability, use pause to pause audio, and play to resume.

Titanium.Media.Sound
playing : Booleanreadonly

Indicates if the audio is playing.

Indicates if the audio is playing.

Titanium.Media.Sound
time : Number

Current playback position of the audio.

Current playback position of the audio.

Time is reported in milliseconds.

On iOS, prior to Release 3.0, playback time is reported in seconds.

Titanium.Media.Sound
url : String

URL identifying the audio resource.

URL identifying the audio resource.

Titanium.Media.Sound
volume : Number

Volume of the audio from 0.0 (muted) to 1.0 (loudest).

Volume of the audio from 0.0 (muted) to 1.0 (loudest).

This setting controls the volume of the sound relative to the overall volume setting for the device.

On iOS, to adjust the volume of the device, set the volume property of Titanium.Media.appMusicPlayer and set the Titanium.Media.audioSessionMode property to either Titanium.Media.AUDIO_SESSION_CATEGORY_SOLO_AMBIENT, Titanium.Media.AUDIO_SESSION_CATEGORY_PLAYBACK, or Titanium.Media.AUDIO_SESSION_CATEGORY_PLAYBACK.

Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

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.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • 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

  • void
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Titanium.Media.Sound
( ) : Number
Gets the value of the audioType property. ...

Gets the value of the audioType property.

  • 6.2.0

Returns

  • Number
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.Media.Sound
( ) : Number
Gets the value of the duration property. ...

Gets the value of the duration property.

Returns

  • Number
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.Media.Sound
( ) : Number
Gets the value of the time property. ...

Gets the value of the time property.

Returns

  • Number
Titanium.Media.Sound
( ) : String
Gets the value of the url property. ...

Gets the value of the url property.

Returns

  • String
Titanium.Media.Sound
( ) : Number
Gets the value of the volume property. ...

Gets the value of the volume property.

Returns

  • Number
Titanium.Media.Sound
( ) : Boolean
Returns the value of the looping property. ...

Returns the value of the looping property.

Returns

  • Boolean
Titanium.Media.Sound
( ) : Boolean
Returns the value of the paused property. ...

Returns the value of the paused property.

Returns

  • Boolean
Titanium.Media.Sound
( ) : Boolean
Returns the value of the playing property. ...

Returns the value of the playing property.

Returns

  • Boolean
Titanium.Media.Sound
( )
Pauses the audio. ...

Pauses the audio.

To restart the audio, call play.

Returns

  • void
Titanium.Media.Sound
( )
Starting playing the sound, or resume playing a paused sound. ...

Starting playing the sound, or resume playing a paused sound.

Returns

  • void
Titanium.Media.Sound
( )
Releases all internal resources. ...

Releases all internal resources.

This is typically unnecessary but can be useful if you load a large audio file in app.js, and play it only once and you would like to release all resources after your final play to reduce memory.

Returns

  • void
Removes the specified callback as an event listener for the named event. ...

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 : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Titanium.Media.Sound
( )
Resets the audio playback position to the beginning. ...

Resets the audio playback position to the beginning.

Returns

  • void
Titanium.Media.Sound
( audioType )
Sets the value of the audioType property. ...

Sets the value of the audioType property.

  • 6.2.0

Parameters

  • audioType : Number

    New value for the property.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Titanium.Media.Sound
( looping )
Sets the value of the looping property. ...

Sets the value of the looping property.

Parameters

  • looping : Boolean

    New value for the looping property.

Returns

  • void
Titanium.Media.Sound
( paused )
Sets the value of the paused property. ...

Sets the value of the paused property.

On iOS, this method can be used to pause and unpause playback. For portability, it is preferable to use the pause and play methods instead.

  • 0.8
  • 0.8

Parameters

  • paused : Boolean

    Pass true to pause the current playback temporarily, false to unpause it.

Returns

  • void
Titanium.Media.Sound
( time )
Sets the value of the time property. ...

Sets the value of the time property.

Parameters

  • time : Number

    New value for the property.

Returns

  • void
Titanium.Media.Sound
( url )
Sets the value of the url property. ...

Sets the value of the url property.

Parameters

  • url : String

    New value for the property.

Returns

  • void
Titanium.Media.Sound
( volume )
Sets the value of the volume property. ...

Sets the value of the volume property.

Parameters

  • volume : Number

    New value for the property.

Returns

  • void
Titanium.Media.Sound
( )
Stops playing the audio and resets the playback position to the beginning of the clip. ...

Stops playing the audio and resets the playback position to the beginning of the clip.

Returns

  • void
Defined By

Events

Titanium.Media.Sound
Fired when the state of the playback changes. ...

Fired when the state of the playback changes.

This event can be generated by programmatic events, such as pausing or stopping the audio, and also by external events, such as the current state of network buffering.

  • 3.2.0

Properties

Titanium.Media.Sound
Fired when the audio has finished playing. ...

Fired when the audio has finished playing.

Properties

  • success : Boolean

    Indicates if the sound was played successfully. Returns true if request succeeded, false otherwise.

    •  
    •  
    •  
  • error : String

    Error message, if any returned. Will be undefined if success is true.

    •  
    •  
    •  
  • code : Number

    Error code. Error code will be 0 if success is true, nonzero otherwise. If the error was generated by the operating system, that system's error value is used. Otherwise, this value will be -1.

    •  
    •  
    •  
  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Titanium.Media.Sound
Fired when an error occurs while playing the audio. ...

Fired when an error occurs while playing the audio.

Properties

  • success : Boolean

    Indicates a successful operation. Returns false.

    •  
    •  
    •  
  • error : String

    Error message, if any returned. May be undefined.

    •  
    •  
    •  
  • code : Number

    Error code. If the error was generated by the operating system, that system's error value is used. Otherwise, this value will be -1.

    •  
    •  
    •  
  • message : String

    Error message. Use the error property instead.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Titanium.Media.Sound
Fired when audio playback is interrupted by the device. ...

Fired when audio playback is interrupted by the device.

Typically called during an interruption due to an incoming phone call.

  • 0.8
  • 0.8

Properties

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Titanium.Media.Sound
Fired when audio playback is resumed after an interruption. ...

Fired when audio playback is resumed after an interruption.

  • 0.8
  • 0.8

Properties

  • interruption : Boolean

    Indicates if the resume was from an interruption.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •