0
votes

In Safari (11), a static audio file loaded into a src via html or javascript works, albeit with the limitations of requiring user input before playing.

ex.

<audio src="static.mp3">

or

var audio = new Audio('static.mp3');
audio.play();

work fine. However, I need to load audio files from the database, so I was using a controller action like so:

public FileContentResult GetAudio(int audioId)
    {
        if (!DbContext.Audios.Any(a => a.Id == audioId))
        {
            return null;
        }

        var audio = DbContext.Audios.Single(a => a.Id == audioId);
        return File(audio.File, "audio/mp3");
    }

and set like

<audio src="getaudio?audioId=1">

or

var audio = new Audio('getaudio?audioId=1');

it will not play in MacOS (Safari) or iOS, but works fine in Chrome and Edge (except on iOS). Depending on how I configure things, I get some form of Unhandled Promise error. I've also tried loading into a Web Audio buffer, with the same exact success and failures.

Does anyone have a solution or workaround to load my audio files on Safari?

EDIT

Ok, so on further testing, I discovered that it's not so much whether the files were sent via action or static file, it's how they were saved to the database in the first place. I'm now working to figure out why files I save (as byte[]) and then reload are not recognized by Safari.

1
If you check the server logs does it report a successful response?Tratcher
Always successful from the server. No errors. I've got an update I'll post here in a sec.Tim

1 Answers

0
votes

OK, so it turns out, I was making the recordings with MediaRecorder, which is a fairly new feature in Chrome and a few other browsers. It didn't matter what format I told it to save as, because only webm is supported. And guess who doesn't support webm format? Safari. Any other browser was picking it up fine, regardless of what incorrect extension I put on the file.

When I find a webm to m4a conversion, I will add it here. I'm sure there are some solutions out there.