HTML5 Audio using AudioJS may not function reliably when loaded remotely

I have been encountering frustrating issues with loading audio tags for a while now. Despite spending nearly two weeks trying to solve the problems, every fix seems to create another one.

My webpage includes an < audio > tag that utilizes audio.js to manage the audio playback. The trouble begins when this page is loaded through an iframe. To keep track of play counts, I have experimented with different methods.

Method One:

To serve an MP3 file to the player and maintain the play count, I use a PHP file. While this setup works flawlessly in Firefox and Chrome (with < audio > tags on the page), it encounters issues in Internet Explorer, possibly due to a PHP-related Gateway Error.

When loading a page containing < audio > tags into an iframe or via AJAX, the audio file loads up to three times. If the player is set to autoplay, the music plays twice simultaneously. Even after pausing the player, the music persists until the iframe is removed using developer tools.

Possible Solution: Although my attempts to load the audio files via AJAX have not been successful, I managed to address the multiple-playback issue by setting autoplay to true in the AudioJS API. However, Internet Explorer still struggles with my PHP-served MP3 file.

Method Two:

An alternative approach involves directly loading the MP3 file, which works across all browsers if embedding the player within a page. Yet, when the player is loaded externally (through an iframe or AJAX), it streams smoothly on Firefox and Internet Explorer but takes longer to load on Google Chrome. It also tends to load the file thrice and play twice, especially noticeable when autoplay is enabled. This method uses JavaScript to update play information in the database.

Possible Solution: I attempted appending a random number to the MP3 URL (?t=4892393) to prompt Chrome to reload the MP3, but the issue persisted. Trying the Flash Fallback option, I found it unresponsive and prone to malfunctions in certain configurations, leading to distorted sound in some cases.

EDIT: Referring to https://github.com/kolber/audiojs/issues/96 on the audiojs GitHub page, I tested the suggested solution without success.

Goal: While Audiojs functions seamlessly when directly embedded in a page, complications arise when loading it externally. Despite examining PHP error logs, checking Dev Console on various browsers, analyzing access logs, and inspecting headers through Fiddler, I remain unable to resolve this issue.

If no resolution is viable due to the outdated nature of audiojs (last updated in 2011), I welcome recommendations for a simple, customizable audio-only player. Thus far, nothing has matched the functionality of audiojs.

Thank you.

Here is a jsFiddle link showcasing the problem, where opening the dev tools reveals triple-loading behavior. While the outcomes are inconsistent, the repetitive loading remains a constant observation.

It's worth noting that everything functions correctly if the player isn't contained within an iframe.

<audio preload="auto" src="/audio/2032c11a6f10a5d21eb91202cf67edd3.mp3" type="audio/mp3" autoplay> </audio>

UPDATE: After further investigation, it appears that the issue occurs only when audio autoplays within the <audio> tags on Firefox and Chrome. Additionally, Chrome experiences extended loading times when the audio player is nested in an iframe.

UPDATE 2: Upon scrutinizing the HTTP headers, it was observed that browsers request a GZIPed MP3 file.

The .htaccess file contains the following compression configuration:

(filter_module)
FilterDeclare COMPRESS

FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = 'text/html'"
...
</IfModule>

During the RAW MP3 file request, the headers show:

First MP3 HTTP Request

Request

GET http://tabbidesign.com/audio/2032c11a6f10a5d21eb91202cf67edd3.mp3 HTTP/1.1
...

Response

HTTP/1.1 200 OK
...

Second MP3 HTTP Request

Request

GET http://tabbidesign.com/audio/2032c11a6f10a5d21eb91202cf67edd3.mp3 HTTP/1.1
...

The response mirrors that of the first request.

Answer №1

When attempting to load in Chrome, it appears to try loading the file twice. Here are a few things to consider:

Ensure that the file is being served with the correct mime-type by adding the following to your .htaccess file:

AddType audio/mp3 .mp3 .m4a

It seems like your server has gzip enabled, which compresses everything before sending, including mp3 files which are already compressed. Comparing the headers of the first and second requests, the second request's header "Accept-Encoding" does not specify gzip, potentially explaining why the second request works. You may want to disable Apache compression in apache.conf or .htaccess, or adjust it to only compress certain file types.

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript

I hope this information helps and wish you luck in resolving the issue!

For more details, check out:

How to disable Apache gzip compression for some media files in .htaccess file?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Synchronized loops in jQuery using the .each method

I'm having trouble getting the ajaxStop function in jquery to work. Any suggestions on how to make it fire? My goal is to iterate through each anchor tag and update some content within it. After that, I want to use the ajaxstop event to trigger a scr ...

The process of eliminating body padding in Nuxt.js

I'm considering building a website using Nuxt.js because I've heard it's both cool and user-friendly. While I do have some knowledge of vue.js, I'm stuck on a particular issue: How can I remove the padding from the body? I understand ...

Using Angular with OpenStreetMap and $routeProvider allows for dynamic routing and

Check out this awesome single page app that I found: https://github.com/tombatossals/angular-leaflet-directive/blob/master/examples/simple-example.html However, I am looking to enhance it by adding a menu... <html ng-app="App"> <head> <lin ...

Incorporate data from a CSV file into an HTML table on the fly with JavaScript/jQuery

I have a CSV file that is generated dynamically by another vendor and I need to display it in an HTML table on my website. The challenge is that I must manipulate the data from the CSV to show corrected values in the table, only displaying products and not ...

What is the reason behind Firefox failing to display a linear gradient when the background-size values are more than 255px?

I am working on creating a grid overlay using an absolutely positioned non-interactive div. My approach involves using the repeating-linear-gradient property as suggested by others for this purpose. The functionality works smoothly in Chrome, but I seem to ...

What is the method to advance the opposing line in the dynamic chart?

Here is the link to the code for a dynamic graph. I am struggling with keeping the red line updated and moving forward together with the blue line. I cannot figure out why the red line remains static in the dynamic graph. Any suggestions on how to solve t ...

JavaScript Looping through multiple files for upload will return the last file in the series

I'm currently working on implementing a multiple file upload feature using JavaScript. Within my HTML, I have the following input: <input type="file" (change)="fileChange($event,showFileNames)" multiple /> When the onChange event is triggere ...

What is the best way to handle requests once a SpookyJS script has finished running?

Occasionally, I find myself needing to log in and extract some data from a specific website. To automate this process, I developed a CasperJS script that runs on Heroku. My goal is to create an endpoint like the following: app.get('/test', func ...

What is the correct way to pass parameters when using the setState() function in React hooks?

I am working on a project where I have a list of country names. When a user clicks on one of the countries, I want to update the state with the name of the newly selected country. This state change will then trigger other changes in a useEffect(). The stat ...

Tips for troubleshooting JavaScript errors in Internet Explorer 7 & 6 using Dreamweaver CS3

Is there a way to track and debug JavaScript errors in Internet Explorer 7 & 6 on web pages using Dreamweaver CS3? I am experienced with debugging in Visual Studio, but unsure how to do it in Dreamweaver CS3. ...

Having trouble retrieving textfield value with jQuery

On my website, I have an invoice.jsp page that requires jQuery to calculate values in textboxes. Within the invoice, there is a quantity textbox. When a user enters a quantity, the price should be dynamically calculated as (total_subPrice= unit_price * qu ...

Removing unnecessary JSP files from your project

During the development of my website, I am heavily relying on Ajax calls to retrieve and display information. The Ajax Calls are structured as follows: function deleteBookingAjax(rowId) { $.ajax({ url : "deleteRent.htm", type : "GET", da ...

Modifying the default event handler signature for an ASP UpdatePanel: A guide

Throughout my experience, I have always relied on standard Asp.net Controls alongside AjaxControlToolkit, never encountering any issues. However, recently I had to utilize Dundas Charting controls, which are not standard .NET controls, and now I need to co ...

Cross-origin resource sharing in Express.js servers

Encountering a minor issue with the connection setup between my Express.js API and React client. The Express API is running on http://localhost:3001, while React is hosted at http://exampleip:3000 (both on the same Windows server). To address Cross-Origi ...

Transforming an Axios image stream into a string by encoding it with Base64?

Currently, this is what I have in place: const Fs = require('fs') const Path = require('path') const Axios = require('axios') var {Base64Encode} = require('base64-stream'); const url = 'https://unsplash.co ...

Tips for organizing components in jQuery Mobile

Displaying a survey creation form: <!-- HTML structure --> <div data-role="page" data-theme="b"> <div data-role="header"> <h1> Create Survey </h1> </div> <div id="main" data ...

Configuring a custom domain for a Rust service on Clever Cloud: A step-by-step guide

After successfully deploying my Rust service to the Clever Cloud platform and testing it on PROD and localhost, I am now facing the challenge of binding my custom domain with the deployed service. I would like to eliminate the need for using the lengthy C ...

Incorporate a JavaScript variable within the src attribute of a script tag

Embedding Google's script allows for displaying a trends Map on our website. <script type="text/javascript" src="//www.google.com.pk/trends/embed.js?hl=en-US&q=iphone&cmpt=q&content=1&cid=TIMESERIES_GRAPH_0&export=5&w=500&a ...

Reactstrap and React-router v4 are failing to redirect when there is a partial change in the address link

Within the header of my website, <NavItem> <NavLink tag={Link} to="/template/editor">Create New Template</NavLink> </NavItem> On the routing page of my website, <BrowserRouter> <div className="container-fluid"> ...

I'm encountering an issue with the "z-index: -1" property in React

After creating a form placed alongside buttons, I encountered an issue where the form overlaps the buttons and prevents them from being clicked. Despite setting the z-index to -1, it seems that the form remains clickable even when not visible. Research ind ...