Playing Multi-sound

When you implement an app that plays multi-sound which are background music and sound effects, you need to read carefully the following guidelines and sample code.

In this article, the audio element and Web Audio API are mentioned for playing multi-sound. Due to restriction, we strongly recommend using the audio element for playing background music.

Using Audio Element

You should use only one audio element in a webOS TV app. As the audio tag uses hardware decoder and app switching is supported, sometimes media resource conflict occurs. To prevent the media resource conflict in webOS TV, only one audio element should be used in a web app. When you declare one or more audio elements in your app, sounds are not played at the same time.

  • The duration of audio content must be at least 1 second.

  • On app suspend, you should pause the sound and resume it when the app goes foreground. Refer to the sample code.

  • Multi-sound works with multiple audio elements in webOS TV Emulator which are working differently from the real device.

Use Case for Audio Element

Playing background music in an application.

Supported MIME Types

Following MIME types are supported in audio element:

  • audio/aac 

  • audio/mp4 

  • audio/x-m4a 

  • audio/mpeg 

  • audio/x-mpeg 

  • audio/x-mp3 

  • audio/mp3

The following example shows that a file of the mp3 format is played with the audio element.

<audio controls autoplay>
  <source type="audio/mp3" src="http://media.w3.org/2010/05/sound/sound_300.mp3"/>
</audio>

Using Web Audio API

Web Audio API is a high-level JavaScript API for processing and synthesizing audio in a web application.

For your reference, see Web Audio API specifications and references below.

createMediaElementSource() method is not supported on webOS TV.

As only one audio element can be used in an app, you should use Web Audio API for playing sound effects.

When playing sound with Web Audio API, it has about 500-millisecond latency issue in webOS TV, so you should be aware of this before using Web Audio API in your app. 

When you use sound effect longer than 1 second, you must stop the sound on app suspend because the platform does not automatically stop the sound of Web Audio API with app suspend. Refer to the sample code.

Use Case for Web Audio API

Playing sound effects in an application.

Supported Media Formats

webOS TV Platform Version

Supported formats

v1.2

Only raw files (pcm, wav)

v2.0, v3.0

  • Raw files (pcm, wav)

  • mp3 

Other Sound Formats

You cannot use SoundFont in webOS TV, which is a file format and associated technology for the computer music composition which mostly contains multiple sounds inside.

 

Navigation