Autoplay audio in WordPress

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for WordPress Development Stack Exchange.

Closed 12 months ago.

I am using the plugin ‘WP Maintenance Mode’ to load a under maintenance website on a website.

I would like for audio to play as soon as somebody lands on the website and for audio player to remain invisible.

BACK SOON

[audio src="//myWebsite/wp-content/uploads/2021/03/audio.mp3"]

This will load the page and show the audio player and it will play when I press play

I have tried

[audio src="//myWebsite/wp-content/uploads/2021/03/audio.mp3 width = "0" height = "0" autoplay=1]

to try and get it to play automatically and without the audio player, but no success.

3

The WordPress Audio Player plugin is a compact HTML5 + flash hybrid  based WordPress plugin which can be used to play an audio file [.mp3 or .ogg]. The audio player is compatible with all major browsers and devices [Android, iPhone].

  • If you are selling audio files from your site then you can use this plugin to offer a preview
  • If you do podcasting then this audio player can be used to embed the audio files on WordPress posts or pages
  • The audio player is compact so it doesn’t take a lot of real estate on your webpage
  • HTML5 compatible so the audio files embedded with this plugin will play on iOS devices

Audio Player Plugin Screenshot

The following images show how the audio player looks when it is playing and not playing a music file:

The following is a preview of how the audio player looks when using template 1:



When the play button is clicked, the button will change to a pause button allowing users to pause the music playback.

Audio Player Plugin Installation and Usage

  1. Go to the ‘Add New’ plugins screen in your WordPress admin area
  2. Click the ‘upload’ tab
  3. Browse for the plugin file [sc_audio_player.zip]
  4. Click ‘Install Now’ and then activate the plugin
  5. Use the following shortcode to embed an audio file anywhere on your site

[sc_embed_player fileurl="URL OF THE MP3 FILE"]

Example shortcode:

[sc_embed_player fileurl="//www.example.com/wp-content/uploads/my-music/mysong.mp3"]

Additional Usage Documentation

Using Auto Play Option

Use the “autoplay” parameter in the shortcode to play the audio file on page load. Here is an example shortcode with autoplay option:

[sc_embed_player autoplay=true fileurl="//www.example.com/wp-content/uploads/my-music/mysong.mp3"]

Specifying a Volume Level

Use the optional “volume” parameter in the shortcode to specify a volume level for the audio. You can use a value between 0 – 100 for the volume level. Here is an example shortcode usage:
[sc_embed_player volume="50" fileurl="//www.example.com/wp-content/uploads/my-music/mysong.mp3"]
The above will set the volume level of the audio file to 50.

Looping the Sound

Use the “loops” parameter in the audio player shortcode to loop an audio file playback automatically. Here is an example shortcode usage with auto loop:
[sc_embed_player loops="true" fileurl="//www.example.com/wp-content/uploads/my-music/mysong.mp3"]

Specifying Both MP3 and OGG Files for the Audio

Note: You don’t really need to use this option. You can just use the mp3 option and the plugin will make sure that the file is playable in all devices.

You can specify both the files types in the “fileurl” parameter separating them with a “|” character. Here is an example shortcode usage that is specifying both the .mp3 and .ogg version of the audio file:
[sc_embed_player loops="true" fileurl="//www.example.com/my-audio.mp3|//www.example.com/my-audio.ogg"]
The plugin will play the supported file based on the user’s device.

Wrapping Text Around the Audio Player

If you want to wrap some text around the audio player then use the following in the “Text” view of the post/page editor:

My Audio:

[sc_embed_player fileurl="//www.example.com/my-music/mysong.mp3"] Alternatively, use the following in the “Text” view of the post/page editor [wrap the audio player shortcode in another CSS class with float]:

Some example text

[sc_embed_player fileurl="//www.example.com/my-music/mysong.mp3"]

Audio Player Template 1

A few users have asked us to add a player template that has a seek bar and volume control. Audio player template1 gives you that option:

Use the following shortcode to embed the audio player using template 1:

[sc_embed_player_template1 fileurl="//www.example.com/wp-content/uploads/my-music/mysong.mp3"]

The above shortcode will produce an output like the following preview:

This template1 shortcode supports “autoplay” and “loops” parameters too. Here is an example:

[sc_embed_player_template1 fileurl="//www.example.com/my-music/mysong.mp3" autoplay="true" loops="true"]

Misc Tips and Tweaks

Remove the White Pixel/Dot on Black Background

If you are using a WordPress theme with black background then you may notice a very small white dot below the audio player. Add the following block of CSS code to your theme’s CSS file to get rid of it:

#sm2-container{ bottom: 0px; }

Adding the Audio Player to a Theme’s Template File

You can also embed the audio player in your theme’s template file. Here is an example code that you can add to your template file:

Chủ Đề