Skip to content

Dynamically changing src doesn't change duration #1755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
PideaLtd opened this issue Mar 7, 2025 · 1 comment
Open

Dynamically changing src doesn't change duration #1755

PideaLtd opened this issue Mar 7, 2025 · 1 comment
Labels

Comments

@PideaLtd
Copy link

PideaLtd commented Mar 7, 2025

Feature Proposal

I'm putting together a web page that receives JSON data containing, among other things, a URL to an MP3. The JSON is pushed via websockets to the page.

When the page first loads I need to play a clip to allow the browser to permit audio so I play a 2 second silent MP3.

Using the solution outlined here:

#825

I can use a single instance of Howler and can change the audio source but the duration does not change so only the first 2 seconds of my clips play.

If I increase the size of the silent MP3 file that I first play to 10 seconds then reload the page, the first 10 seconds of my clips play but they can vary in length from 2 to 60 seconds.

I've tried changing the proposed changeSrc function so that:

self.unload(true);

becomes:

self.unload(false);

but that makes no difference. Is there a way to force Howler to pick up the new duration ?

Possible Implementation

No response

@mogamoga1024
Copy link

mogamoga1024 commented Mar 10, 2025

loadイベントが発火してから処理をしたらどうなるんだろうか?

要するにこういうこと

function changeSrc(howl, src) {
    return new Promise((resolve, reject) => {
        howl.unload();
        howl.once("load", () => resolve(howl));
        howl.once("loaderror", (id, error) => reject({id, error}));
        howl._src = src;
        howl.load();
    });
}

(どうでもいいがunload関数は引数を取らない。)
(そもそもHowler.jsは自動的にオーディオを許可すると思う。)
(Howlオブジェクトを再生成するのは駄目なのだろうか?XY問題では?)
(html5プロパティはtrue?false?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants