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

The feature of Access Control Request Headers involves appending certain information to the header of an AJAX request when using jQuery

Looking to enhance an AJAX POST request from jQuery with a custom header. Attempted solution: $.ajax({ type: 'POST', url: url, headers: { "My-First-Header":"first value", "My-Second-Header":"second value" } ...

Initiate Child Event within Parent Component

Before switching tabs in the parent component, I want the child tab to validate itself. My idea is to pass the onActive event from the parent to its children, <ClientInfo/> and <Details/>. This will allow the children to validate themselves a ...

Employing varying data objects sent from views to templates based on user's button selection

In my current project, I have a model named Comments. Upon submitting a youtube Channel in a form, the user is directed to the index template displaying all comments on videos from that channel containing one of three keywords (Keyword A, Keyword B, Keywo ...

The connection was refused by hapi.js

We have recently encountered an issue while using hapijs: hapi, {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","domainEmitter":{"domain":{"domain":null,"_events":{},"_maxListeners":10,"members":[]},"_events":{},"_maxListeners":10},"doma ...

Here is a way to prevent a null input value from being accepted in a JavaScript function

Hey there, I have a function that looks like this: class Fun { pem_Files_Checker_And_Adder_Server_Id_Adder(id , serverType , hostname) { //do something }; }; } In order for this function to work properly, I need to give it some values. For exam ...

Turn off Jquery Mobile Ajax Navigation

After countless hours spent poring over API documentation and online forums, I still can't seem to disable the AJAX Navigation feature. CURRENT SETUP <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script src="htt ...

Renewal of a personalized linestring layer in MapBox GL JS triggered by a Geocoder event

I am currently using MapBox GL JS and I have a requirement to redraw a linestring layer whenever a Geocoder.on event occurs. Upon examining my code, I noticed that the linestring only gets drawn on the first .on event, and nothing happens during subsequen ...

Can you explain the purpose and function of stub.callsArg(index) feature in Sinon.JS?

Confusion has set in as I try to make sense of this. According to the documentation: stub.callsArg(index) - This command prompts the stub to execute the callback function found at the specified index. For instance, using stub.callsArg(0); will trigger the ...

A guide on effectively mocking functions in Jest tests with Rollup.js

I am currently in the process of developing a React library called MyLibrary, using Rollup.js version 2.58.3 for bundling and jest for unit testing. Synopsis of the Issue The main challenge I am facing is with mocking a module from my library when using j ...

Building a single-page app optimized for mobile viewing with Foundation framework

Currently facing an issue with the scaling of the viewport on certain mobile devices when loading new content via ng-include in our responsive website built on Foundation. The problem arises as the width of the page breaks, leading to horizontal scrolling. ...

Having an iframe at the bottom of the page is causing unnecessary white space below the

I currently have an iframe placed in the footer of my website. When I try to set the height of the iframe to match the height of the footer, it results in unwanted white space appearing below the iframe. The issue can be seen here: JSFiddle To fix this p ...

What is causing the error to appear in the Android web-view when using vue.js?

During the development of my web app using Vue.js, I encountered a strange issue where everything was functioning correctly in desktop browsers but not on mobile devices. To troubleshoot this problem, I decided to install an Android emulator and use remote ...

Deliver data in batches of ten when the endpoint is accessed

I am currently in the process of developing a web application using Next.JS and Node. As part of this project, I have created my own API with Node that is being requested by Next.JS. One particular endpoint within my API sends data to the front end as an ...

Using jQuery to interact with a web service - overcoming cross-domain restrictions

Attempting to connect to a WCF service using a jQuery client. Referencing this specific example: http://www.codeproject.com/KB/aspnet/WCF_JQUERY_ASMX.aspx#4 Everything functions properly when the client webpage is on the same domain as the service. Howe ...

Obtaining an element in the Document Object Model (DOM) following

There are numerous questions and answers regarding this issue, but I am struggling to adapt it to my specific case. My extension fetches positions (1,2,...100) on the scores pages of a game. Upon initial page load, I receive the first 100 positions. Howev ...

Tips for retrieving the HTML file of a modified canvas in HTML5

I’m currently working on a project to develop a website that allows users to design their own pages by simply dragging and dropping elements onto the canvas. The goal is for users to be able to save their creations as an HTML file. I’m facing challen ...

Avoid reloading the page in PHP when the browser back button is clicked

I've built an HTML form where the values are passed to a second page using POST method. On the second page, I have an edit button that, when clicked, redirects back to the HTML form page with the user's typed values. However, my dilemma is figuri ...

Mongoose retrieves the entire document, rather than just a portion of it

I'm currently experiencing an issue with my mongoose query callback from MongoDB. Instead of returning just a specific portion of the document, the code I'm using is returning the entire document. I have verified that in the database, the 'p ...

Loading Google Maps with Ajax

Exploring the world of google maps has been quite entertaining for me, however, I find myself in need of some assistance. The issue at hand involves a small block of HTML/Javascript that can be seamlessly integrated into a standard HTML page or loaded into ...

What is the best way to retrieve a promise from several promises?

Every time I check the console, I see the following: teamsUpdated2 addUserToProjects deleteUserFromProjects However, they should be displayed in a different order. var result = teamService.addOrDeleteUser(userId, newTeams, deleteTeams); result.then(fun ...