Skip to content
Titanium SDK
Version13.0.0

You are reading 13.0.0. See this page in 13.4.1.

Titanium.Media

moduleAndroidiPhoneiPadmacOSsince 0.1

Extends Titanium.ModuleTitanium.Proxy

The top-level Media module.

The Media module is used to access the device's media-related functionality, such as using the device's camera and photo gallery, playing media files, or recording audio or video. For examples of using the Media APIs, refer to the Working with Media APIs guide in addition to the other media submodule API documentation. Note: Some third party Android camera apps may choose to ignore video recording quality settings. If you wish to specifically set the video quality, don't assume EXTRA_VIDEO_QUALITY intent will be respected by the camera app and use Titanium's built-in camera window which can be used to assign the overlay property when calling the showCamera() method.

Properties 178

apiName

Stringsince Android 3.2.0, iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0read-only

Inherited from Titanium.Proxy

The name of the API that this proxy corresponds to.

AUDIO_FILEFORMAT_AIFF

NumberiPhoneiPadmacOSread-only

Audio file format Audio Interchange File Format (AIFF).

AUDIO_FILEFORMAT_CAF

NumberiPhoneiPadmacOSread-only

Audio file format Apple Compressed Audio Format (CAF).

AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD

StringiPhoneiPadmacOSsince 3.4.2read-only

Session mode for recording (input) and playback (output) of audio, such as for a VOIP (voice over IP) application.

This category is appropriate for simultaneous recording and playback, and also for applications that record and play back but not simultaneously. If you want to ensure that sounds such as Messages alerts do not play while your application is recording, use Titanium.Media.AUDIO_SESSION_CATEGORY_RECORD instead. This category normally disallows mixing iPod audio with application audio.

In this mode, by default audio playback is routed to the speaker in the iPhone receiver. To have audio playback through the iPhone speaker, use Titanium.Media.setOverrideAudioRoute.

AUDIO_SESSION_CATEGORY_PLAYBACK

StringiPhoneiPadmacOSsince 3.4.2read-only

Session mode for playing recorded music or other sounds that are central to the successful use of your application.

When using this mode, your application audio continues with the Ring/Silent switch set to silent or when the screen locks. This property normally disallows mixing iPod audio with application audio.

AUDIO_SESSION_CATEGORY_SOLO_AMBIENT

StringiPhoneiPadmacOSsince 3.4.2read-only

Session mode for long-duration sounds such as rain, car engine noise, and so on.

When you use this category, audio from built-in applications, such as the iPod, is silenced. Your audio is silenced when the Ring/Silent switch is set to silent or when the screen locks.

To use long-duration sounds without silencing built-in applications, see AUDIO_SESSION_CATEGORY_AMBIENT.

AUDIO_SESSION_PORT_AIRPLAY

StringiPhoneiPadmacOSsince 3.4.2read-only

Constant for output on a remote Air Play device. This is an output port.

AUDIO_SESSION_PORT_BLUETOOTHHFP

StringiPhoneiPadmacOSsince 3.4.2read-only

Constant for input or output on a Bluetooth Hands-Free Profile device. This can be both an input and output port.

AUDIO_SESSION_PORT_BLUETOOTHLE

StringiPhoneiPadmacOSsince 3.4.2read-only

Constant for output on a Bluetooth Low Energy device. This is an output port. This is available on iOS7 and later.

AUDIO_SESSION_PORT_CARAUDIO

StringiPhoneiPadmacOSsince 3.4.2read-only

Constant for Input or output via Car Audio. This can be both an input and output port. This is available on iOS7 and later.

AUDIO_SESSION_PORT_HDMI

StringiPhoneiPadmacOSsince 3.4.2read-only

Constant for output via High-Definition Multimedia Interface. This is an output port

AUDIO_SESSION_PORT_LINEIN

StringiPhoneiPadmacOSsince 3.4.2read-only

Constant for line level input on a dock connector. This is an input port.

AUDIO_SESSION_PORT_LINEOUT

StringiPhoneiPadmacOSsince 3.4.2read-only

Constant for line level output on a dock connector. This is an output port.

AUDIO_SESSION_PORT_USBAUDIO

StringiPhoneiPadmacOSsince 3.4.2read-only

Constant for input or output on a Universal Serial Bus device. This can be both an input and output port.

audioPlaying

BooleaniPhoneiPadmacOSread-only

Returns true if the device is playing audio.

audioSessionCategory

StringiPhoneiPadmacOSsince 3.4.2

A constant for the audio session category to be used.

Set to one of the AUDIO_SESSION_CATEGORY constants defined in Titanium.Media.

Must be set while the audio session is inactive (no sounds are playing, no listeners for audio properties on the Media module, but the iPod may be active).

bubbleParent

Booleansince Android 3.0.0, iPhone 3.0.0, iPad 3.0.0, macOS 9.2.0

Inherited from Titanium.Proxy

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

Default: true

CAMERA_AUTHORIZATION_AUTHORIZED

NumberiPhoneiPadmacOSsince 4.0.0read-only

Constant specifying that app is authorized to use camera. This is available on iOS7 and later.

CAMERA_AUTHORIZATION_DENIED

NumberiPhoneiPadmacOSsince 4.0.0read-only

Constant specifying that app is denied usage of camera. This is available on iOS7 and later.

CAMERA_AUTHORIZATION_RESTRICTED

NumberiPhoneiPadmacOSsince 4.0.0read-only

Constant specifying that app is restricted from using camera. This is available on iOS7 and later.

CAMERA_AUTHORIZATION_UNKNOWN

NumberiPhoneiPadmacOSsince 5.2.0read-only

Constant specifying that app is not yet authorized to use camera. This is available on iOS7 and later.

CAMERA_FLASH_AUTO

Numbersince Android 3.3.0, iPhone 1.4.0, iPad 1.4.0read-only

Constant specifying to have the device determine to use the flash or not.

CAMERA_FLASH_OFF

Numbersince Android 3.3.0, iPhone 1.4.0, iPad 1.4.0read-only

Constant specifying to never fire the flash.

CAMERA_FLASH_ON

Numbersince Android 3.3.0, iPhone 1.4.0, iPad 1.4.0read-only

Constant specifying to always fire the flash.

CAMERA_FRONT

Numbersince 3.2.0read-only

Constant specifying the front camera.

CAMERA_REAR

Numbersince 3.2.0read-only

Constant indicating the rear camera.

cameraOutputSizes

ObjectAndroidsince 12.2.0read-only

Returns an object of possible targetImageWidth and targetImageHeight values. The output contains a cameraType (front or back) and object of width/height values. You have to set targetImageWidth and targetImageHeight if you want to change the camera image output size. Note: depeneding on your phone and camera the values won't be used or can be different.

canRecord

Booleansince 6.2.0read-only

true if the device has a recording input device available.

currentRoute

RouteDescriptioniPhoneiPadmacOSsince 3.4.2read-only

Returns a description of the current route, consisting of zero or more input ports and zero or more output ports.

DEVICE_BUSY

Numberread-only

Constant for media device busy error.

IMAGE_SCALING_ASPECT_FILL

Numbersince 10.1.0read-only

Crops the image proportionally causing its content to be clipped either horizontally or vertically.

IMAGE_SCALING_ASPECT_FIT

Numbersince 10.1.0read-only

Letterbox or pillarbox scales the image proportionally to fit the container.

IMAGE_SCALING_FILL

Numbersince 10.1.0read-only

Stretches the image disproportionally to completely fill the container's bounds.

IMAGE_SCALING_NONE

Numbersince 10.1.0read-only

Disables scaling and displays the image as-is.

maxZoomLevel

NumberAndroidsince 12.2.0read-only

Returns the max zoom level of the camera.

MEDIA_TYPE_LIVEPHOTO

StringiPhoneiPadmacOSsince 5.2.0read-onlyiOS 9.1+

Media type constant for live photo media.

Value "com.apple.live-photo"

MEDIA_TYPE_PHOTO

Stringread-only

Media type constant for photo media.

Value "public.image"

MEDIA_TYPE_VIDEO

Stringread-only

Media type constant for video media.

Value "public.movie"

minZoomLevel

NumberAndroidsince 12.2.0read-only

Returns the min zoom level of the camera.

MUSIC_MEDIA_TYPE_ALL

NumberiPhoneiPadmacOSread-only

Music library media containing any type of content.

NO_CAMERA

Numberread-only

Constant for media no camera error.

NO_FOCUS

Numbersince 12.2.1read-only

Constant for camera didn't focus when taking a trying to take a picture.

NO_VIDEO

Numberread-only

Constant for media no video error.

QUALITY_640x480

Numbersince iPhone 0.9.0, iPad 0.9.0, Android 7.5.0read-only

Media type constant for medium-quality video recording.

If recording, specifies that you want to use VGA-quality video recording (pixel dimensions of 640x480).

QUALITY_FHD

NumberAndroidsince 12.2.0read-only

Media type constant for FHD video recording.

QUALITY_HD

NumberAndroidsince 12.2.0read-only

Media type constant for HD video recording.

QUALITY_HIGH

Numbersince iPhone 0.9.0, iPad 0.9.0, Android 7.5.0read-only

Media type constant for high-quality video recording.

Recorded files are suitable for on-device playback and for wired transfer to the Desktop using Image Capture; they are likely to be too large for transfer using Wi-Fi.

QUALITY_IFRAME_1280x720

Numbersince Android 7.5.0, iPhone 6.0.0, iPad 6.0.0read-only

Media type constant for medium-quality video recording.

If recording, specifies that you want to use 1280x720 iFrame format.

QUALITY_IFRAME_960x540

NumberiPhoneiPadmacOSsince 6.0.0read-only

Media type constant for medium-quality video recording.

If recording, specifies that you want to use 960x540 iFrame format.

QUALITY_LOW

Numbersince iPhone 0.9.0, iPad 0.9.0, Android 7.5.0read-only

Media type constant for low-quality video recording.

Recorded files can usually be transferred over the cellular network.

QUALITY_MEDIUM

NumberiPhoneiPadmacOSread-only

Media type constant for medium-quality video recording.

Recorded files can usually be transferred using Wi-Fi. This is the default video quality setting.

QUALITY_SD

NumberAndroidsince 12.2.0read-only

Media type constant for SD video recording.

QUALITY_UHD

NumberAndroidsince 12.2.0read-only

Media type constant for UHD video recording.

torch

BooleanAndroidsince 12.2.0

Enable or disable the camera torch.

useCameraX

BooleanAndroidsince 12.2.0read-only

To use the new CameraX classes for "camera with overlay" set useCameraX to true

Default: false

VIDEO_CONTROL_DEFAULT

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Constant for default video controls.

Used in conjunction with the mediaControlStyle property of Titanium.Media.VideoPlayer.

Removed on iOS in SDK 7.0.0.

VIDEO_CONTROL_EMBEDDED

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Constant for video controls for an embedded view.

Used in conjunction with the mediaControlStyle property of Titanium.Media.VideoPlayer.

On Android, this constant has the same effect as VIDEO_CONTROL_DEFAULT. Video controls may only be shown or hidden.

Removed on iOS in SDK 7.0.0.

VIDEO_CONTROL_FULLSCREEN

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Constant for fullscreen video controls.

Used in conjunction with the mediaControlStyle property of Titanium.Media.VideoPlayer.

On iOS, use VIDEO_CONTROL_FULLSCREEN when creating a video player that occupies the entire screen, that is, the parent window should be a fullscreen window (fullscreen set to true) and the video player should occupy the entirety of the parent window.

If the user clicks the Done button in the fullscreen control bar, the video player pauses playback and generates a complete event.

Note that if you create a video player that does not occupy the entire screen, and later switch to fullscreen mode, the video controls are switched automatically. That is, if mediaControlStyle is set to VIDEO_CONTROL_DEFAULT or VIDEO_CONTROL_EMBEDDED, it is automatically switched to the fullscreen controls when the player enters fullscreen mode. This is true whether the user initiates the mode switch by clicking the fullscreen button in the embedded controls, or if you programmatically switch to full screen mode (by setting the fullscreen property to true).

On Android, this constant has the same effect as VIDEO_CONTROL_DEFAULT. Video controls may only be shown or hidden.

Removed on iOS in SDK 7.0.0.

VIDEO_CONTROL_HIDDEN

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Constant for video controls hidden.

Used in conjunction with the mediaControlStyle property of Titanium.Media.VideoPlayer.

Removed on iOS in SDK 7.0.0.

VIDEO_CONTROL_NONE

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Constant for no video controls.

Used in conjunction with the mediaControlStyle property of Titanium.Media.VideoPlayer.

Removed on iOS in SDK 7.0.0.

VIDEO_LOAD_STATE_FAILED

NumberiPhoneiPadmacOSread-only

Indicates that the player can no longer play media items because of an error.

Video playback is rewinding.

This constant has been removed on iOS in SDK 7.0.0 by using the official Apple AVPlayer that does not expose this functionality so far.

Video playback is seeking forward.

This constant has been removed on iOS in SDK 7.0.0 by using the official Apple AVPlayer that does not expose this functionality so far.

VIDEO_REPEAT_MODE_NONE

Numbersince Android 6.2.0, iPhone 0.9.0, iPad 0.9.0read-only

Constant for disabling repeat on video playback.

VIDEO_REPEAT_MODE_ONE

Numbersince Android 6.2.0, iPhone 0.9.0, iPad 0.9.0read-only

Constant for repeating one video (i.e., the one video will repeat constantly) during playback.

VIDEO_SCALING_ASPECT_FILL

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

Use <Titanium.Media.VIDEO_SCALING_RESIZE_ASPECT_FILL> instead.

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Scale video to fill the screen, clipping edges if necessary.

Video is scaled until the video fills the entire screen. Content at the edges of the larger of the two dimensions is clipped so that the other dimension fits the screen exactly. The aspect ratio of the movie is preserved.

VIDEO_SCALING_ASPECT_FIT

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

Use <Titanium.Media.VIDEO_SCALING_RESIZE_ASPECT> instead.

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Scale video to fit the screen, letterboxing if necessary.

Video is scaled until the larger dimension fits on the screen exactly. In the other dimension, the region between the edge of the movie and the edge of the screen is filled with a black bar. The aspect ratio of the movie is preserved.

This constant was removed on iOS in SDK 7.0.0

VIDEO_SCALING_MODE_FILL

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

Use <Titanium.Media.VIDEO_SCALING_MODE_RESIZE> instead.

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Video is scaled until both dimensions fit the screen exactly, stretching if necessary.

This constant was removed on iOS in SDK 7.0.0

VIDEO_SCALING_NONE

NumberdeprecatedAndroidread-only

Deprecated since 7.0.0

This property has been removed for iOS in Titanium SDK 7.0.0 as of the official deprecation by Apple.

Video scaling is disabled.

This constant was removed on iOS in SDK 7.0.0

VIDEO_SCALING_RESIZE

String | Numbersince iPhone 7.0.0, iPad 7.0.0, Android 8.3.0read-only

Specifies that the video should be stretched to fill the bounds of layer.

This is a String on iOS, a Number on Android.

VIDEO_SCALING_RESIZE_ASPECT

String | Numbersince iPhone 7.0.0, iPad 7.0.0, Android 8.3.0read-only

Specifies that the player should preserve the aspect ratio of video and fit the video within the bounds of layer.

This is a String on iOS, a Number on Android.

VIDEO_SCALING_RESIZE_ASPECT_FILL

String | Numbersince iPhone 7.0.0, iPad 7.0.0, Android 8.3.0read-only

Specifies that the player should preserve the aspect ratio of video and fill the bounds of layer.

This is a String on iOS, a Number on Android.

volume

NumberiPhoneiPadmacOSread-only

Current volume of the playback device.

A value in the range 0.0 to 1.0, with 0.0 representing the minimum volume and 1.0 representing the maximum volume.

zoomLevel

NumberAndroidsince 12.2.0

Sets the zoom level of the camera.

Methods 39

Inherited from Titanium.Proxy

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

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to invoke when the event is fired.

4 fields
bubbles Boolean

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

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

beep

iPhoneiPadmacOS

Plays a device beep notification.

Inherited from Titanium.Proxy

Fires a synthesized event to any registered listeners.

Parameters
ParametersTypeDescription
nameString

Name of the event.

event?Dictionary

A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

hasAudioPermissions

deprecatediPhoneiPadmacOSsince 6.0.0

Deprecated since 6.1.0, removed in 10.0.0

Returns true if the app has audio permissions.

Recording audio requires explicit permission from the user. After the user grants or denies permission, the system remembers the choice for future use in the same app. If permission is not granted, or if the user has not yet responded to the permission prompt, any audio recording sessions record only silence.

In addition, Apple introduced the Info.plist key NSMicrophoneUsageDescription that is used to display an own description while authorizing microphone permissions. In iOS 10, this key is mandatory and the application will crash if your app does not include the key. Check the Apple docs for more information.

Returns Boolean

hasAudioRecorderPermissions

since Android 6.2.0, iPhone 6.1.0, iPad 6.1.0

Returns true if the app has audio permissions.

Recording audio requires explicit permission from the user. After the user grants or denies permission, the system remembers the choice for future use in the same app. If permission is not granted, or if the user has not yet responded to the permission prompt, any audio recording sessions record only silence.

In addition, Apple introduced the Info.plist key NSMicrophoneUsageDescription that is used to display an own description while authorizing microphone permissions. In iOS 10, this key is mandatory and the application will crash if your app does not include the key. Check the Apple docs for more information.

Returns Boolean

hasMusicLibraryPermissions

iPhoneiPadmacOSsince 6.0.0

Returns true if the app has music library access.

Music-library permissions are only needed in iOS 9.3 and later and will be ignored on older iOS versions. Because of that, the method will return true for devices that run iOS < 9.3.

Returns Boolean

hasPhotoGalleryPermissions

since Android 9.3.0, iPhone 6.0.0, iPad 6.0.0

Returns true if the app has photo gallery permissions.

If you use Android 13+ you have to add the following permissions to your tiapp.xml:

<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>

You don't need to check this before using Titanium.Media.requestPhotoGalleryPermissions. If you already have the permission and use Titanium.Media.requestPhotoGalleryPermissions it will call the success event, no second permission request is displayed.

Returns Boolean

hideCamera

since 3.2.0

Hides the device camera UI.

Must be called after calling showCamera and only when autohide is set to false. This method causes the media capture UI to be hidden.

isMediaTypeSupported

iPhoneiPadmacOS

Returns true if the source supports the specified media type.

You can query whether a given media type is supported by the device's camera (source == 'camera') or photo library (source == 'photo').

An additional value, photogallery can be used to query the media supported by the device's camera roll or saved image album, which is a subset of the iOS photo library. However, when calling openPhotoGallery on iOS, the entire library is displayed, and there is currently no way to restrict the gallery to show only the camera roll/saved images album.

Parameters
ParametersTypeDescription
sourceString

Media source specified as a string: camera for Camera or photo for Photo Library.

typeString

Media type to check.

Returns Boolean

openMusicLibrary

iPhoneiPadmacOS

Shows the music library and allows the user to select one or more tracks.

If autohide is set to false, you must hide the library explicitly using hideMusicLibrary.

Parameters
ParametersTypeDescription
optionsMusicLibraryOptionsType

A dictionary of options as described in MusicLibraryOptionsType.

7 fields
allowMultipleSelections Boolean

Set to true to allow the user to select multiple items from the library.

animated Boolean

Boolean if the dialog should be animated when showing and hiding.

autohide Boolean

Specifies that the library should be hidden automatically after media selection is completed.

cancel Callback<FailureResponse>

Function to call if the user presses the cancel button.

error Callback<FailureResponse>

Function to call upon receiving an error.

mediaTypes Number | Array<Number>

An array of media type constants defining selectable media.

success Callback<MusicLibraryResponseType>

Function to call when the music library selection is made.

Opens the photo gallery image picker.

In iOS 6, Apple introduced the Info.plist key NSPhotoLibraryUsageDescription that is used to display an own description while authorizing gallery permissions. In iOS 10, this key is mandatory and the application will crash if your app does not include the key. Check the Apple docs for more information.

Parameters
ParametersTypeDescription
optionsPhotoGalleryOptionsType

Photo gallery options as described in PhotoGalleryOptionsType.

14 fields
allowEditing Boolean

Specifies if the media should be editable after capture/selection.

allowMultiple Boolean

Specifies if the user should be able to select multiple photos.

allowTranscoding Boolean

Specifies if the video should be transcoded (using highest quality preset) . If set to false no video transcoding will be performed.

animated Boolean

Specifies if the dialog should be animated upon showing and hiding.

arrowDirection Number

Controls the type of arrow and position of the popover.

autohide Boolean

Specifies if the photo gallery should be hidden automatically after the media selection is completed.

cancel Callback<FailureResponse>

Function to call if the user presses the cancel button.

error Callback<FailureResponse>

Function to call upon receiving an error.

maxImages Boolean

Specifies the number of images a user can select at maximum.

mediaTypes Array<String>

Array of media type constants to allow.

Live photos is only supported on the iOS platform, starting with iOS 9.1. If you want to allow live photos with Titanium.Media.MEDIA_TYPE_LIVEPHOTO, you also need to specify at least Titanium.Media.MEDIA_TYPE_PHOTO as a fallback. If you do not allow live photos, they still can be selected, but will be represented as a normal static photo.

pathOnly Boolean

Do not include the blob in the result

popoverView Titanium.UI.View

View to position the photo gallery popover on top of.

selectionLimit Boolean

Specifies number of media item that can be selected.

success Callback<CameraMediaItemType> | Callback<CameraMediaMultipleItemsType>

Function to call when the photo gallery is closed after a successful selection.

Displays the given image.

Parameters
ParametersTypeDescription
optionsDictionary<PreviewImageOptions>

Dictionary containing the image and callback functions.

queryMusicLibrary

iPhoneiPadmacOS

Searches the music library for items matching the specified search predicates.

Use Titanium.Media.hasMusicLibraryPermissions to check the granted permissions and Titanium.Media.requestMusicLibraryPermissions to request the permissions. This is especially important when running on an iOS 10 device, because the music-library access will crash without having the privacy-key NSAppleMusicUsageDescription that is specified in Titanium.Media.requestMusicLibraryPermissions.

Parameters
ParametersTypeDescription
queryMediaQueryType

The query object to extract information from.

Returns Array<Titanium.Media.Item>

Inherited from Titanium.Proxy

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

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

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

4 fields
bubbles Boolean

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

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

requestAudioRecorderPermissions

since Android 6.2.0, iPhone 6.1.0, iPad 6.1.0

Request the user's permission for audio recording.

Recording audio requires explicit permission from the user. After the user grants or denies permission, the system remembers the choice for future use in the same app. If permission is not granted, or if the user has not yet responded to the permission prompt, any audio recording sessions record only silence.

In addition, Apple introduced the Info.plist key NSMicrophoneUsageDescription that is used to display an own description while authorizing microphone permissions. In iOS 10, this key is mandatory and the application will crash if your app does not include the key. Check the Apple docs for more information.

Parameters
ParametersTypeDescription
callback?Callback<MediaAuthorizationResponse>

Callback function to execute when the users responds to the authorization alert. Optional on SDK 10, as this method will return a Promise, which may be used to handle the result.

Returns Promise<MediaAuthorizationResponse>

On SDK 10+, this method will return a Promise whose resolved value is equivalent to that passed to the optional callback argument.

Requests for camera access.

On Android, the request view will show if the permission is not accepted by the user, and the user did not check the box "Never ask again" when denying the request. If the user checks the box "Never ask again," the user has to manually enable the permission in device settings.

This method requests Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE and Manifest.permission.WRITE_EXTERNAL_STORAGE on Android. If you require other permissions, you can also use Titanium.Android.requestPermissions.

In iOS 6, Apple introduced the Info.plist key NSCameraUsageDescription that is used to display an own description while authorizing camera permissions. In iOS 10, this key is mandatory when taking a photo and the application will crash if your app does not include the key. Check the Apple docs for more information. When using the camera to take a video, you also need the NSMicrophoneUsageDescription key. In addition, the authorization dialog will only show if user has not made a decision, yet. If the user has, the callback will return the earlier decision. To change the permission the user needs to change it in the device settings.

Parameters
ParametersTypeDescription
callback?Callback<RequestCameraAccessResult>

Function to call indicating if permission was granted or denied. Optional on SDK 10, as this method will return a Promise, which may be used to handle the result.

Returns Promise<RequestCameraAccessResult>

On SDK 10+, this method will return a Promise whose resolved value is equivalent to that passed to the optional callback argument.

requestMusicLibraryPermissions

iPhoneiPadmacOSsince 6.0.0

Request permissions for the native music-library.

Music-library permissions are only needed in iOS 9.3 and later and will be ignored on older iOS versions. Because of that, the callback will ignore the permission-check and always return {success: true} for devices that run iOS < 9.3.

Important: On iOS 10, Apple introduced the Info.plist key NSAppleMusicUsageDescription that is used to display an own description while authorizing the music library. This key is mandatory and the application will crash if your app does not include the key. Check the Apple docs for more information.

Parameters
ParametersTypeDescription
callbackCallback<RequestMusicLibraryAccessResult>

Function to call indicating if permission was granted or denied.

requestPhotoGalleryPermissions

since Android 9.3.0, iPhone 6.0.0, iPad 6.0.0

Requests for photo gallery permissions.

In iOS 6, Apple introduced the Info.plist key NSPhotoLibraryUsageDescription that is used to display an own description while authorizing photo gallery permissions. In iOS 10, this key is mandatory when accessing the photo gallery and the application will crash if your app does not include the key. Check the Apple docs for more information. If the user has, the callback will return the earlier decision. To change the permission the user needs to change it in the device settings.

iOS Apps that do not include this method, will present the system-dialog while the dialog is opened with Titanium.Media.openPhotoGallery.

If you use Android 13+ you have to add the following permissions to your tiapp.xml:

<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>

When you only want to use it for images you can use [Titanium.Android.requestPermissions](api:Titanium.Android#requestPermissions) and request android.permission.READ_MEDIA_IMAGES.

Parameters
ParametersTypeDescription
callback?Callback<RequestPhotoGalleryAccessResult>

Function to call indicating if permission was granted or denied. Optional on SDK 10, as this method will return a Promise, which may be used to handle the result.

Returns Promise<RequestPhotoGalleryAccessResult>

On SDK 10+, this method will return a Promise whose resolved value is equivalent to that passed to the optional callback argument.

Saves media to the device's photo gallery / camera roll.

This operation is asynchronous. The caller can supply callbacks to be triggered when the save operation completes.

Media can be passed as either a Blob object or a File object. If the media argument is not one of these types, an error is generated.

Note that when passing a file (or a blob created from a file), the file name must have the appropriate extension for the data--for example, image.jpg or video1.mov work, but video1.tmp does not. Currently, the .mp4 extension is not supported, but MP4 files may be imported by saving them with the .mov extension.

Make sure to check for gallery access permissions with Titanium.Media.hasPhotoGalleryPermissions and request the permissions with Titanium.Media.requestPhotoGalleryPermissions if not granted. On iOS, the NSPhotoLibraryAddUsageDescription plist key is required in the tiapp.xml in order to use this API.

On Android, this method does not support saving videos to the gallery prior to Titanium SDK 6.1.0.

Parameters
ParametersTypeDescription
mediaTitanium.Blob | Titanium.Filesystem.File

Media to save to the camera roll or media gallery.

callbacksObject

Pass a dictionary with the following supported keys: success a function that will be called when the save succeeds, and error a function that will be called upon receiving an error.

setOverrideAudioRoute

iPhoneiPadmacOS

Overrides the default audio route when using the Titanium.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD session mode.

By default, when using the Titanium.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD session mode, the audio output is routed to the speaker in the receiver. This method lets you specify that audio should be routed to the built-in speaker.

If you override the audio route while audio is playing the changes won't not take effect until the audio is restarted.

Parameters
ParametersTypeDescription
routeNumber

The specified audio route.

Shows the camera.

By default, the native camera controls are displayed. To add your own camera controls, you can add an overlay view by setting the overlay property on the options argument.

Android Platform Notes

  • To suppress the default controls, set autohide to false and then set the overlay property to a view that contains a control (such as a button) to take the photo. You must then control the camera explicitly, using the takePicture and hideCamera methods.
  • Setting saveToPhotoGallery to false is not guaranteed to work with all camera apps. If this setting is desired, then you should use Titanium's internal camera overlay instead.
  • You can only use one or the other (video or photo) types in the array.

iOS Platform Notes

To suppress the default controls, set showControls and autohide to false.

If the showControls option is false, you must control the camera explicitly, using the takePicture and hideCamera methods.

Images taken with the camera will not have accurate geolocation data embedded in the images; the latitude and longitude will be set to '0'. This is not an error, but a limitation which Apple has put on the camera API.

Important: Use Titanium.Media.hasCameraPermissions and Titanium.Media.requestCameraPermissions to ask for camera permissions. This is especially important when running on iOS 10 and later, since the application may crash otherwise.

Parameters
ParametersTypeDescription
optionsCameraOptionsType

A dictionary of camera options as described in CameraOptionsType.

24 fields
allowEditing Boolean

Specifies if the media should be editable after capture/selection.

androidback Callback<FailureResponse>

Function to call if the user presses the back button.

animated Boolean

Specifies if the dialog should be animated upon showing and hiding.

arrowDirection Number

Controls the type of arrow and position of the popover.

autohide Boolean

Specifies if the camera should be hidden automatically after the media capture is completed.

autorotate Boolean

Determines if the camera preview should rotate or not.

cancel Callback<FailureResponse>

Function to call if the user presses the cancel button.

error Callback<FailureResponse>

Function to call upon receiving an error.

inPopOver Boolean

Show the camera in a popover.

mediaTypes Array<String>

Array of media type constants to allow. Note: If you want to select live photos, iOS only allows you to select existing live photos from the gallery, capturing new live photos is not supported by iOS public API, yet.

open Callback<CameraOpen>

Function to call when the camera is shown

overlay Titanium.UI.View

View to added as an overlay to the camera UI (on top).

popoverView Titanium.UI.View

View to position the camera or photo gallery popover on top of.

recording Callback<CameraRecordingCallback>

Function to call during recording. Returns size and duration.

saveToPhotoGallery Boolean

Specifies if the media should be saved to the photo gallery upon successful capture.

showControls Boolean

Indicates if the built-in camera controls should be displayed.

success Callback<CameraMediaItemType>

Function to call when the camera is closed after a successful capture/selection.

targetImageHeight Number

Maximum height of the saved image. Depending on your phone and your value this might not be exactly the value you specify. Check Ti.Media.cameraOutputSizes first.

targetImageWidth Number

Maximum width of the saved image. Depending on your phone and your value this might not be exactly the value you specify. Check Ti.Media.cameraOutputSizes first.

transform Titanium.UI.Matrix2D

Transformation matrix to apply to the camera or photogallery view.

videoMaximumDuration Number

Maximum duration (in milliseconds) to allow video capture before completing.

videoQuality Number

Constant to indicate the video quality during capture.

whichCamera Number

Opens the camera with the specified camera direction.

zoomEnabled Boolean

Specifies if pinch to zoom is enabled or not.

switchCamera

since Android 3.2.0, iPhone 1.8.1, iPad 1.8.1

Switches between front and rear-facing cameras. Make sure to set one of the below constants to determine the camera you want to switch to.

In Android, this can only be called when using a custom overlay (see Titanium.Media.showCamera).

Parameters
ParametersTypeDescription
cameraNumber

Constant indicating to which camera you want to switch.

Uses the device camera to capture a photo.

Must be called after calling showCamera and only when autohide is set to false.

This method causes the media capture device to capture a photo and call the success callback.

Takes a screen shot of the visible UI on the device.

This method is asynchronous. The screenshot is returned in the callback argument. The callback argument's media property contains the screenshot image as a Blob object.

Parameters
ParametersTypeDescription
callbackCallback<ScreenshotResult>

Function to call upon capture.

1 field
media Titanium.Blob

The screenshot image.

Makes the device vibrate.

On Android, a pattern argument can be provided to specify a vibration pattern.

The pattern is an array of Number values. Each number in the array is interpreted as a duration in milliseconds. The first number is the delay before the pattern starts, and the remaining numbers are interpreted as alternating periods of on and off times. For example, the following pattern:

[ 0, 500, 100, 500, 100, 500 ]

Would cause the vibration to start immediately (delay = 0), and perform three long vibrations (500 ms) separated by short pauses (100ms).

Parameters
ParametersTypeDescription
pattern?Array<Number>

Array of values identifying a vibrate pattern (only used on Android).

Events 3

cameraready

Androidsince 6.0.0

Fires when the camera overlay is ready to take pictures.

routechange

iPhoneiPadmacOSsince 3.4.2

Fired when an audio line type change is detected.

Event properties
Event propertiesTypeDescription
reasonString

The reason for route change.

oldRouteRouteDescription

Returns a description of the old route, consisting of zero or more input ports and zero or more output ports.

2 fields
inputs Array<String>

An Array of current input ports for the session. See the AUDIO_SESSION_PORT constants.

outputs Array<String>

An Array of current output ports for the session. See the AUDIO_SESSION_PORT constants.

currentRouteRouteDescription

Returns a description of the current route, consisting of zero or more input ports and zero or more output ports.

2 fields
inputs Array<String>

An Array of current input ports for the session. See the AUDIO_SESSION_PORT constants.

outputs Array<String>

An Array of current output ports for the session. See the AUDIO_SESSION_PORT constants.

volume

iPhoneiPadmacOS

Fired when the volume output changes.

Event properties
Event propertiesTypeDescription
volumeNumber

New volume level in dB.