user1460255
user1460255

Reputation: 55

How to load remote URL as MP3

I'm trying to load an MP3 from a remote URL so that I can play it. I'm using Howler.js. I'm able to load URLs that end in ".mp3" but I'm trying to load a URL like this:

var sound = new Howl({
    src: ['https://qualtrics.com/ControlPanel/File.php?F=F_Rjgarh85'],
    autoplay: true,
    loop: true,
    volume: 0.5,
});

(I broke the link for privacy reasons.)

The sound fails to load in Howler.js, but I know it's loadable with something like the HTML tag.

What's going on with the PHP request? How can I load it like a normal mp3?

The full story is that I'm trying to have some dynamic audio in Qualtrics using their javascript integration. Because I'm not actually hosting the server, I'm not able to store mp3s on a local server and access them that way - but I can store the files in the Qualtrics "Files Library." Am I going about this the correct way?

Upvotes: 2

Views: 3100

Answers (1)

James Simpson
James Simpson

Reputation: 13718

You need to use the format property if the type isn't in the extension (https://github.com/goldfire/howler.js#format-array-):

var sound = new Howl({
    src: ['https://qualtrics.com/ControlPanel/File.php?F=F_Rjgarh85'],
    format: ['mp3'],
    autoplay: true,
    loop: true,
    volume: 0.5,
});

Upvotes: 5

Related Questions