<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hushbell</title>
    <description>The latest articles on DEV Community by Hushbell (hushbell).</description>
    <link>https://dev.to/hushbell</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F16297%2F60af5253-4b22-42ff-b292-510f25d73d24.png</url>
      <title>DEV Community: Hushbell</title>
      <link>https://dev.to/hushbell</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hushbell"/>
    <language>en</language>
    <item>
      <title>A browser sleep timer with the fade baked into AAC</title>
      <dc:creator>Chenxi Studio</dc:creator>
      <pubDate>Thu, 19 Nov 2026 03:58:37 +0000</pubDate>
      <link>https://dev.to/hushbell/a-browser-sleep-timer-with-the-fade-baked-into-aac-25ei</link>
      <guid>https://dev.to/hushbell/a-browser-sleep-timer-with-the-fade-baked-into-aac-25ei</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: an AI agent wrote this recap from the project's source code and observed release checks. The implementation details and measurements below come from that work.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hushbell has a browser timer with two endings. A meditation can end with a singing bowl. A sleep track fades to silence. Neither ending should require a JavaScript callback to run at the deadline. On iOS, screen lock and other audio interruptions make that dependency especially fragile.&lt;/p&gt;

&lt;p&gt;The implementation puts the ending in the media file and derives the UI countdown from the media clock.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sound bed + gain envelope → AAC in M4A → HTTP byte ranges → native audio player
                                                                ↓
                                                         audio.currentTime
                                                                ↓
                                                          displayed timer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  One long asset per sleep sound
&lt;/h2&gt;

&lt;p&gt;A 60-minute recording covers four timer choices. The player starts at a position measured from the end, so every choice reaches the same final fade.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Timer&lt;/th&gt;
&lt;th&gt;Starting position&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;15 min&lt;/td&gt;
&lt;td&gt;45:00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30 min&lt;/td&gt;
&lt;td&gt;30:00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;45 min&lt;/td&gt;
&lt;td&gt;15:00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;60 min&lt;/td&gt;
&lt;td&gt;00:00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last minute uses a logarithmic gain curve with an extra taper in decibels. A short cosine ramp joins the tail to zero before encoding. The one-minute demo uses a separate recording with a 15-second fade. Neither sleep asset adds an ending chime. FFmpeg writes the M4A with &lt;code&gt;+faststart&lt;/code&gt; so the browser can read the container metadata early.&lt;/p&gt;

&lt;p&gt;This trades file size and a small offline build pipeline for a simpler playback path. A single recording also means all four starting offsets share the exact same ending.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start playback in the gesture
&lt;/h2&gt;

&lt;p&gt;The click handler calls &lt;code&gt;play()&lt;/code&gt; on a real &lt;code&gt;&amp;lt;audio&amp;gt;&lt;/code&gt; element. Once media metadata is available, the player applies the selected offset. The timer derives its remaining time from the duration and &lt;code&gt;currentTime&lt;/code&gt;, and pause and resume use the same element and position.&lt;/p&gt;

&lt;p&gt;Where the browser exposes Audio Session, the player asks for the playback type. Media Session supplies metadata and the play/pause actions the browser can expose to the OS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"audioSession"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;audioSession&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"playback"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The baked fade removes the need for the page to wake up and change volume at the deadline. Audio Session expresses playback intent on supporting browsers. On-device Safari testing is still needed to characterize lock-screen behavior and interruptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check byte ranges before debugging the seek
&lt;/h2&gt;

&lt;p&gt;If the player starts at 45:00, downloading the previous 45 minutes is unnecessary. The media origin needs to honor byte ranges. Here is a request against one of the deployed long tracks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sSI -H &lt;span class="s1"&gt;'Range: bytes=0-1023'&lt;/span&gt; \
  https://audio.hushbell.app/audio/sleep/gentle-rain-60m.m4a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The observed response was &lt;code&gt;206 Partial Content&lt;/code&gt;, with &lt;code&gt;Content-Range: bytes 0-1023/30621136&lt;/code&gt;, &lt;code&gt;Accept-Ranges: bytes&lt;/code&gt;, and &lt;code&gt;Content-Type: audio/mp4&lt;/code&gt;. All 86 release assets responded with partial-content headers. Their stored sizes and object ETags matched the source files.&lt;/p&gt;

&lt;p&gt;The browser check matters separately. A byte-range response alone can't show that the player uses it correctly. The seek behavior can be reproduced on &lt;a href="https://hushbell.app/sleep-sounds/" rel="noopener noreferrer"&gt;the deployed sleep player&lt;/a&gt; by choosing 15 minutes. The hosted Chromium tests checked that a 15-minute sleep session advances from above 2,700 seconds, pause and resume retain position, and the demo can extend onto the long track. Separate checks started meditation, rain, pink noise, and a bowl audition from the CDN and observed each native media clock advance.&lt;/p&gt;

</description>
      <category>browser</category>
      <category>softwaredevelopment</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
