You are reading 13.1.0. See this page in 13.4.1.
Titanium.Media.Sound
Extends Titanium.Proxy
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.audioSessionCategory.
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();
Properties 27
Determines whether the audio should continue playing even when its activity is paused.
Default: false
Inherited from Titanium.Proxy
The name of the API that this proxy corresponds to.
Used to identify the volume of audio streams for alarms.
Used to identify the volume of audio streams for media playback.
Used to identify the volume of audio streams for notifications.
Used to identify the volume of audio streams for the phone ring.
Used to identify the volume of audio streams for DTMF tones or beeps.
Used to identify the volume of audio streams for voice calls.
Changes the audio-stream-type.
Default: <Titanium.Media.AudioPlayer.AUDIO_TYPE_MEDIA>
Inherited from Titanium.Proxy
Indicates if the proxy will bubble an event to its parent.
Default: true
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 Titanium.Media.Sound.STATE_INITIALIZED).
Inherited from Titanium.Proxy
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
looping
BooleanDetermines whether the audio should loop upon completion.
Default: false
paused
BooleanIndicates if the audio is paused.
Indicates if the audio is playing.
Audio data is being buffered from the network.
Audio playback is being initialized.
Playback is paused.
Audio playback is active.
Audio playback is starting.
Audio playback is stopped.
Audio playback is stopping.
Player is waiting for audio data from the network.
Player is waiting for audio data to fill the queue.
time
NumberCurrent playback position of the audio.
Time is reported in milliseconds.
On iOS, prior to Release 3.0, playback time is reported in seconds.
url
StringURL identifying the audio resource.
volume
NumberVolume 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.audioSessionCategory property
to either Titanium.Media.AUDIO_SESSION_CATEGORY_SOLO_AMBIENT,
Titanium.Media.AUDIO_SESSION_CATEGORY_PLAYBACK,
or Titanium.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD.
Methods 14
Inherited from Titanium.Proxy
Adds the specified callback as an event listener for the named event.
| Parameters | Type | Description |
|---|---|---|
| name | String | Name of the event. |
| callback | Callback<Titanium.Event> | Callback function to invoke when the event is fired. 4 fields
|
applyProperties
since 3.0.0Inherited from Titanium.Proxy
Applies the properties to the proxy.
| Parameters | Type | Description |
|---|---|---|
| props | Dictionary | A dictionary of properties to apply. |
Inherited from Titanium.Proxy
Fires a synthesized event to any registered listeners.
| Parameters | 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. |
isLooping
deprecatedDeprecated since 10.0.0
Use the <Titanium.Media.Sound.looping> property instead.
Returns the value of the looping property.
isPaused
deprecatedDeprecated since 10.0.0
Use the <Titanium.Media.Sound.paused> property instead.
Returns the value of the paused property.
isPlaying
deprecatedDeprecated since 10.0.0
Use the <Titanium.Media.Sound.playing> property instead.
Returns the value of the playing property.
Pauses the audio.
To restart the audio, call play.
Starting playing the sound, or resume playing a paused sound.
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.
Inherited from Titanium.Proxy
Removes the specified callback as an event listener for the named event.
| Parameters | Type | Description |
|---|---|---|
| name | String | Name of the event. |
| callback | Callback<Titanium.Event> | Callback function to remove. Must be the same function passed to 4 fields
|
Resets the audio playback position to the beginning.
setLooping
deprecatedDeprecated since 10.0.0
Set the value of the looping property directly.
Sets the value of the looping property.
| Parameters | Type | Description |
|---|---|---|
| looping | Boolean | New value for the |
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.
| Parameters | Type | Description |
|---|---|---|
| paused | Boolean | Pass |
Stops playing the audio and resets the playback position to the beginning of the clip.
Events 5
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.
| Event properties | Type | Description |
|---|---|---|
| state | Number | Current state of playback. |
| description | String | Text description of the state of playback. |
Fired when the audio has finished playing.
| Event properties | Type | Description |
|---|---|---|
| success | Boolean | Indicates if the sound was played successfully.
Returns |
| error | String | Error message, if any returned. Will be undefined if |
| code | Number | Error code.
Error code will be |
Fired when an error occurs while playing the audio.
| Event properties | Type | Description |
|---|---|---|
| success | Boolean | Indicates a successful operation. Returns |
| error | String | Error message, if any returned. May be |
| 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 |
| message | String | Error message. |
interrupted
iPhoneiPadmacOSFired when audio playback is interrupted by the device.
Typically called during an interruption due to an incoming phone call.
resume
iPhoneiPadmacOSFired when audio playback is resumed after an interruption.
| Event properties | Type | Description |
|---|---|---|
| interruption | Boolean | Indicates if the resume was from an interruption. |