Click to search on your search term.
Subscribe to Fig Leaf Tutorials

Need help with a project? Contact us at
From code reviews to project "jumpstarts" and full life-cycle development, we've got you covered!
Check out our case studies!
Follow us on Twitter!
Click here to join our Facebook group!

Ready to upgrade your skills? Try these instructor-led classes in Washington, DC:

Working with Audio

Page of 168

The Ext.Audio class (xtype: audio) acts as a wrapper for the html5 <audio> tag.

The recommended file types/compression are:

  • Uncompressed WAV and AIF
  • MP3
  • AAC-LC
  • HE-AAC

You will typically set the following configuration properties:

Config Option Description

String. The URL of the audio file.

autoPause Pauses the media when the container is deactivated.
autoResume Starts playing the audio immediately when the container is activated.
enableControls Boolean. Set to false to turn off native controls. Defaults to false on Android.
muted Boolean. Determines if the media is muted. Sets the volume to 0. Defaults to false.
preload Boolean. Starts downloading the media immediately. Defaults to true.
volume Number. The volume of the playback in a range of 0.0 to 1.0

Consequently, a simple instantiation of the Ext.Img class resembles the following:

 xtype: 'audio',
 src: '',
 autoResume: true,
 autoPause: true,
 enableControls: true

Ext.Audio and Ext.Video also support the following methods:

Method Description
isPlaying()Returns the current play status as a boolean.
pause()Pauses playback.
play()Continues playback.
stop()Stops playback and returns to the beginning of the loop.
toggle()Toggles the playback state.

Unfortunately, Android devices do not support native audio controls, so to ensure cross-device compatibility, you might want to develop your own custom player, as illustrated by the following example:

Ext.define('MyApp.view.AudioPlayer', {
 extend: 'Ext.Container',
 alias: 'widget.audioplayer',

 config: {
  url: '',
  autoPause: true,
  autoResume: true,
  enableControls: false,
  preload: true,
  layout: {
    type: 'vbox'

 initialize: function() {
   xtype: 'audio',
   url: this.getUrl(),
   autoResume: this.getAutoResume(),
   preload: this.getPreload(),
   autoPause: this.getAutoPause(),
   enableControls: this.getEnableControls()

  if (!this.getEnableControls() || {
    xtype: 'button',
    text: 'Play',
    handler: function(b,e) {
     var audio = this.getParent().down('audio');
     if (audio.isPlaying()) {
       b.setText('Play audio');
      } else {;
       b.setText('Pause Audio');
Page of 168
comments powered by Disqus