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:
Simple example of playing a WAVE file from the Resources directory.
var player = Ti.Media.createSound({url:"sound.wav"});
player.play();
Used to identify the volume of audio streams for alarms.
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 media playback.
Used to identify the volume of audio streams for notifications.
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 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 DTMF tones or beeps.
Used to identify the volume of audio streams for voice calls.
Used to identify the volume of audio streams for voice calls.
Audio data is being buffered from the network.
Audio data is being buffered from the network.
Audio playback is being initialized.
Audio playback is being initialized.
Player is waiting for audio data from the network.
Player is waiting for audio data from the network.
Player is waiting for audio data to fill the queue.
Player is waiting for audio data to fill the queue.
Determines whether the audio should continue playing even when its activity is paused.
Default: false
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
.
Changes the audio-stream-type.
This API can be assigned the following constants:
Default: Titanium.Media.AudioPlayer.AUDIO_TYPE_MEDIA
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
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.
Determines whether the audio should loop upon completion.
Default: false
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.
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.
Adds the specified callback as an event listener for the named event.
Name of the event.
Callback function to invoke when the event is fired.
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.
A dictionary of properties to apply.
Fires a synthesized event to any registered listeners.
Name of the event.
A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.
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.
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);
Name of the event.
Callback function to remove. Must be the same function passed to addEventListener
.
Resets the audio playback position to the beginning.
Sets the value of the audioType property.
New value for the property.
Sets the value of the bubbleParent property.
New value for the property.
Sets the value of the lifecycleContainer property.
New value for the property.
Sets the value of the looping property.
New value for the looping
property.
Sets the value of the volume property.
New value for the property.
Stops playing the audio and resets the playback position to the beginning of the clip.
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.
Current state of playback.
This API can be assigned the following constants:
Text description of the state of playback.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired when the audio has finished playing.
Indicates if the sound was played successfully.
Returns true
if request succeeded, false
otherwise.
Error message, if any returned. Will be undefined if success
is true
.
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 that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired when an error occurs while playing the audio.
Indicates a successful operation. Returns false
.
Error message, if any returned. May be undefined.
Error code. If the error was generated by the operating system, that system's error value is used. Otherwise, this value will be -1.
Error message. Use the error property instead.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired when audio playback is interrupted by the device.
Typically called during an interruption due to an incoming phone call.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired when audio playback is resumed after an interruption.
Indicates if the resume was from an interruption.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.