Sunday, 25 July 2021

How To Add Audio To A Website

 

KARI REDFIELD • APR 10, 2021

How To Add Audio To A Website

You’ve spent a lot of time mapping out a website for your small business customer. You’ve created a beautiful design with great photos, strategically deployed video — and you know what will make it better: the judicious use of sound. 

Sound can be an excellent way to stand out from the competition, help visitors remember information (you know all of those brand jingles in your head?), and build an emotional connection with a brand. Audio can even help with SEO rankings when used in the right way.

In short, audio, when used properly, can be an important component of a website experience. 

Here are several options for embedding audio on a website.

1. AUDIO HOSTING

An easy way to embed audio on a website is by using a sound hosting site, such as SoundCloud or Mixcloud. All you need to do is upload the file and receive an HTML embed code. Then copy and paste the embed code into the web page’s code or WYSIWYG site editor. This works for most CMS platforms and website builders.

2. ADD AN AUDIO WIDGET ON DUDA

Duda’s highly flexible website builder platform features numerous special tools that make it super easy to add audio to a website while retaining control over how it looks and functions. First, follow the steps above to add the audio file to a sound hosting site. Then, to add it to your web page, select the audio widget from the menu and add the link to the audio file.

With Duda, you can set the layout, play icon, and sizing options using the Design Editor.

To access the design editor:

  • Right-click the widget, and click Edit Design.
  • If you are using Mixcloud, you have layout, thumbnail display, light/dark color scheme, and sizing options.
  • If you are using SoundCloud, you have layout, play icon color, and sizing options.

3. USE HTML5

You can code audio into your website with the HTML5 <audio> element. When you code it in with the <audio> command and source attribute (src), the default is the browser’s audio default settings. Or you can define some elements of how the audio will play, such as telling it to autoplay or play muted so the user can choose to turn on sound.

Here’s an example from W3Schools:

 

<audio controls autoplay>

  <source src="horse.ogg" type="audio/ogg">

  <source src="horse.mp3" type="audio/mpeg">

Your browser does not support the audio element.

</audio>

Or muted:

 

<audio controls autoplay muted>

  <source src="horse.ogg" type="audio/ogg">

  <source src="horse.mp3" type="audio/mpeg">

Your browser does not support the audio element.

</audio>

The text between the audio tags will only show if the browser doesn’t support the HTML5 audio element.

4. ADD JAVASCRIPT

If you’re going to code a file into a website instead of using the Duda widget, we recommend using JavaScript in addition to HTML5. JavaScript provides more control to ensure that the audio is integrated into the site and acts as intended. For instance, it allows you to display play, pause, mute, and other control buttons. Other examples: You can set the default to sound off and allow sound to come on with an easy-to-find controller (this is highly recommended because sound can be distracting), and your script can even be programmed to play certain sounds in response to the user’s actions, such as during a quiz.

Here’s an example from JavaScript Tutor for adding a play button and pause controller and script to HTML code:

 

<audio controls id="music">

<source src="mj.mp3" type="audio/mpeg">

Your browser does not support the audio element.

</audio>

 

<p>Click the buttons to play or pause the music.</p>

 

<button onclick="play()" type="button">Play </button>

<button onclick="pause()" type="button">Pause</button>

 

<script>

var myMusic= document.getElementById("music");

function play() {

myMusic.play();

}

 

function pause() {

myMusic.pause();

}

</script>


EMBEDDING AUDIO ON A WEBSITE

When you’re ready to take a website to the next level, add some sound elements to it. Duda makes embedding audio simple. And if you need even more control, you can use JavaScript.

JOIN OUR NEWSLETTER 
AND BE THE FIRST TO KNOW!
Share by:

No comments:

Post a Comment

Latest Browsers Required

The latest versions of the following browsers should be used when registering on the Province’s system:

  • Microsoft Edge Chromium
  • Google Chrome
  • Mozilla Firefox
  • Apple Safari

CES 2021

Your Future Starts here

I know how it feels to be unemployed with no clear path forward

Technology show

Technology show
CES Las Vegas

Search This Blog

CES 2022