TuxedoTako / 4chan-xt

Adds various features to anonymous imageboards.
Other
80 stars 7 forks source link

Sound player issue: short webm with longer audio #36

Closed LeeroyGarfield closed 2 months ago

LeeroyGarfield commented 3 months ago

Unlike gifs and images, which allow audio to play for any duration, webms stop the audio at the end of the video. For example, if the webm lasts 10 seconds but the audio lasts a minute, the audio will stop at exactly 10 seconds and then repeat. Is there a way to remove that limit?

Here's the link to the soundpost that causes this issue: https://boards.4chan.org/vt/thread/70968855#p70970036

I found out about this issue because I realized that the audio must had been longer so I downloaded it and indeed, it was longer than the video.

If you don't mind, would you consider making 4chan sound player compatible or integrate it? Is it possible? I like its features and options.

TuxedoTako commented 3 months ago

The XT implementation is indeed a simple one: if it's a video, it syncs the audio to the video, otherwise it just plays the audio and shows controls.

About 4chan sounds player, I noticed that before. I don't know what exactly broke compatibility, but it seems to be a race condition. It's a simple one line fix.

At the end of 4chan sound player's src/main.js:

 // The timeout makes sure 4chan X will have added it's classes and be identified.
 setTimeout(function () {
    require('./globals');

    // If it's already known 4chan X is installed this can be skipped.
    if (!isChanX) {
        if (document.readyState !== 'loading') {
            doInit();
        } else {
            document.addEventListener('DOMContentLoaded', doInit);
        }
    }
-}, 0);
+}, 500);

That's it. I have no idea how I broke that in the first place. I didn't change XT's @run-at, and the init function isn't async or delayed. It would be a simple change in the userscript, if 4chan sounds player provided a not minified build. So here is a full build with that one line fix: 4chan-sounds-player.user.js.zip (zip because github doesn't allow .js uploads in comments.) I don't know if I should open a PR with that fix, since 4chan sounds player's repo seems dead.

LeeroyGarfield commented 3 months ago

I did your instructions, and that fixed it! I decided to go with duplicating the script and replacing the code with the fix you provided. I know very basic coding after all.

I got really nitpicky about the lack of an icon on the sound button because it only showed "[Sound]", so I decided to edit the script again and followed your way of coding, which fixed it. Finally.

At line 1432:

_.element(`<span id="shortcut-sounds" class="shortcut brackets-wrap icon-shortcut" data-index="0"">

to

`_.element(`<span id="shortcut-sounds" class="shortcut brackets-wrap icon-shortcut" data-index="500" style="--icon: '▶';">

Yeah, 4chan sound player hasn't had any update since 2022, which is a real shame. So this brings up another question: do you plan to improve your sound player with features similar to 4chan sound player in the future?

Also, do you intend to fix the "short webm long audio" issue?

Thank you for your hard work, Tako!

TuxedoTako commented 3 months ago

Also, do you intend to fix the "short webm long audio" issue?

To be honest, I'm not really motivated to work on this at this time. 4chan sound player, despite being dead, still works with the small fix.

LeeroyGarfield commented 3 months ago

I understand. I'm happy with the fix.

Thank you for your hard work.

TuxedoTako commented 3 months ago

I made the audio the source of truth in 2.7.0. I didn't find a video with longer audio, so I didn't actually test that case with the new version yet.

LeeroyGarfield commented 2 months ago

That fixes it. Now it plays the whole audio instead of stopping at the end of the shorter video.

Tested link: https://boards.4chan.org/vt/thread/73172584#p73176276

Just for your information: having both XT's sound player and 4chan sound player script enabled make a chaotic result after the soundpost reaches the end. Obviously, the fix is to disable one of them. Just thought it was funny.

Again, thank you for your hard work.