Controls: AUDIO

What you will learn in this chapter
AUDIO control Attributes, Supported Formats
Reference Tutorial:
Good Read: VIDEO control

AUDIO control can play audio files from various sources

  • Remote Server (via streaming)
  • res/raw folder (on the local device - Android only)
  • Assets folder (on the local device - Android only)
  • Absolute path (on the local device)

The player will stop automatically

  • If a phone call is received
  • If the user taps on the screen playing the audio
  • If the attribute auto_pause=”true” and another screen pops up above the screen playing audio.

Note

Android Only - Add following permission in AndroidManifest.xml file

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

Attributes

Attribute Description Mandatory
name Name identifies this control. If another control wants to include a control as an attribute, then name is used. No
type AUDIO Yes
x

Specifies x position (distance from the left edge of the parent control). Parent control could be screen as well. It can be expressed in percentage, or pixels (px) or device pixels (dp).

By default width in percentage is relative to its parent control. It can be made relative to screen using attribute dimensions_relative_to=”SCREEN” in screen_deck . Learn more about dimensions

Yes
y

Specifies y position (distance from the top edge of the parent control). Parent control could be screen as well. It can be expressed in percentage, or pixels (px) or device pixels (dp).

By default width in percentage is relative to its parent control. It can be made relative to screen using attribute dimensions_relative_to=”SCREEN” in screen_deck . Learn more about dimensions

Yes
width

Specifies the width of the control in percentage or pixels (px) or device pixels (dp).

By default width in percentage is relative to its parent control. It can be made relative to screen using attribute dimensions_relative_to=”SCREEN” in screen_deck . Learn more about dimensions

Yes
height

Specifies the height of the control in percentage or pixels (px) or device pixels (dp).

By default width in percentage is relative to its parent control. It can be made relative to screen using attribute dimensions_relative_to=”SCREEN” in screen_deck . Learn more about dimensions

Yes
appearance_name Gives the appearance name for the control as defined in appearance.xml. Yes
default_value audio file (local or remote) No
data_type Defines the type of data applicable for this control. URL STRING
auto_start Indicates if the audio player should start automatically playing the media upon creation if default_value is set. Default is “true” No
auto_resume Indicates if the audio player should resume automatically when the parent screen resumes. Default is “true”. No
auto_pause Indicates if the audio player should pause automatically when the parent screen pauses No

Supported Formats

Please refer to the list of

Examples

  1. Example: Audio file - Remote Source
<control
    name="audio" type="AUDIOVIEW" appearance_name="1"
    x="0" y="0" width="100" height="100"
    default_value="http://robtowns.com/music/blind_willie.mp3">
</control>
Android iOS
../_images/audio.png
  1. Example: Raw Folder (Android only)
<control
    name="audio" type="AUDIOVIEW" appearance_name="1"
    x="0" y="0" width="100" height="100"
    default_value="raw:blind_willie.mp3">
</control>
  1. Example: Assets Folder (Android only)
<control
    name="audio" type="AUDIOVIEW" appearance_name="1"
    x="0" y="0" width="100" height="100"
    default_value="blind_willie.mp3">
</control>

Note

Android only

  • Raw Folder
    • Is faster to access.
    • Has no size limit to any file.
    • Must be placed in the right location (res/raw).
    • Must have names that are valid Java identifiers
    • Cannot have sub-directories
  • Assets Folder
    • Has no location and name restrictions. In other words the files can be grouped in whatever directories we wish.
    • Has a limit of 1MB for files other than with extensions “jpg, jpeg, png, gif, wav, mp2, mp3, ogg, aac, mpg, mpeg, mid, midi, smf, jet, rtttl, imy, xmf, mp4, m4a, m4v, 3gp, 3gpp, 3g2, 3gpp2, amr, awb, wma, wmv”. So a file of more than 1MB cannot be saved in the asset folder.
  1. Example: Absolute Path
<control
    name="audio" type="AUDIOVIEW" appearance_name="1"
    x="0" y="0" width="100" height="100"
    default_value="/mnt/sdcard/blind_willie.mp3">
</control>