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, audio element and Web Audio API are mentioned for playing multi-sound. Due to restriction, we strongly recommend using 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 app goes foreground. Refer to the sample code.
  • Multi-sound works with multiple audio elements in webOS TV Emulator which is working differently from 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
 
This is an example for playing with audio element of specific format. 
<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 web application.

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

 

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 sound inside.

 

Navigation