Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

When the Provider Returns No Audio Track: Saying So Instead of Offering a Silent File

There is a quiet failure mode in a video downloader that took me too long to notice. A visitor pastes a link, picks the audio option, and gets a file that downloads fine, opens fine, and plays back in total silence. Noth

There is a quiet failure mode in a video downloader that took me too long to notice. A visitor pastes a link, picks the audio option, and gets a file that downloads fine, opens fine, and plays back in total silence. Nothing in the response says anything went wrong. The file is real, and the experience is rubbish.

That happened on ramrom.io, my free downloader, and the cause was a gap between what I assumed a provider would always return and what it actually returns.

The assumption I made

When I first wired up the audio option, my thinking went like this: a video has sound, so an audio download of that video will have sound. The provider sends back a list of formats, my code picks the audio one, and the visitor gets their file. Simple.

It is simple right up until it is not. Some videos genuinely have no audio track. A screen recording with the microphone off. A slideshow set to no music. A clip uploaded silent on purpose. The provider knows this, and its response reflects it: the format list simply contains no audio stream.

My code did not know that. It took the first format labelled audio, and when there was none it fell back to something else without checking what it was handing over. The visitor got a file that looked like an audio download in every way except the one that mattered: it made no sound.

What the check looks like now

The fix is boring, which is why I like it. Before I offer an audio option, resolve.php now looks at the format list the provider returned and asks one question: is there an audio stream here at all?

For each format, I check whether it carries an audio codec and whether its audio bitrate is above zero. A format with a video codec and no audio codec is not an audio download, however good it looks in the list. A format that claims to be audio but reports a zero bitrate is not one either. If nothing in the list passes, the audio option does not appear on the page.

Instead, the visitor sees a plain sentence: this video has no audio track, so there is nothing to download as audio. The video download is still offered, because the pictures are still there. What I stopped doing is offering a download I know will disappoint.

Why I would rather say no

The tempting fix is to offer the file anyway and let the visitor find out. But a silent file is worse than no file, because the visitor has already spent their time and data downloading it. The visitor has no way of knowing the tool did anything wrong, so they blame the video, their phone, or themselves, and try again with another link. Each retry costs me provider quota for a result I already knew would be silent.

Saying "there is no audio here" costs nothing. It is honest, it is fast, and it leaves the visitor with a working choice instead of a broken file. It also makes my logs cleaner: when a visitor reports a silent download now, I can check whether the provider listed an audio stream. If it did and the file is still silent, that is a real bug worth chasing. If it did not, the message on the page already told the visitor why.

The wider habit

This is the same habit I have been building across the whole site: never offer a thing you cannot deliver. The download button waits for a tap instead of firing on paste. The quality dropdown lists what each format really is, instead of guessing at file sizes. The error messages say what actually happened, instead of blaming the visitor's link for a provider outage.

A silent audio file taught me that the absence of a thing is itself information, and the honest move is to pass that information on instead of papering over it with a download that goes nowhere. If a video has no sound, say so. The visitor will respect that far more than a file that plays back in silence.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.