PolyluteDocs polylute.app

Concepts

Why Android must “hear” music

On USB Direct nothing plays through Android, so Polylute plays one silent track that no one can hear, just so Android knows music is on.

On this page

In short

  • On USB Direct the music goes straight to the DAC and never touches Android’s audio system. To Android, it looks as if nothing is playing.
  • Several parts of Android treat “nothing is playing” differently, for example how the volume keys are routed. So Polylute plays one silent track on the phone’s own speaker while Direct plays.
  • It cannot make a sound, it never reaches the DAC, and it costs next to nothing.

How it works

On the Android route, the music is played by Android, so Android knows it is playing. On USB Direct, Polylute sends the samples over USB itself. None of the app’s tracks is playing in Android’s sense, and Android’s own checks, such as is music active?, say no.

Polylute gives Android what it looks for and nothing else: one silent track, alive only while USB Direct is really playing.

Without a silent trackMusic goes to the DAC over USB, but Android sees no player running, so volume keys, ducking and Do Not Disturb rules can miss the music. Without a silent track Music goes to the DAC over USB Android sees no player running Volume keys, ducking and Do Not Disturb rules can miss the music With a silent trackMusic goes to the DAC over USB. A silent track plays on the phone's own speaker, at volume zero, so Android sees music playing. The silent track never reaches the DAC. With a silent track Music goes to the DAC over USB A silent track plays on the phone’s own speaker volume 0, tiny, unheard Android sees music playing The silent track never reaches the DAC
Without and with the silent track. Amber marks the silent track.

In words

Without it: music goes to the DAC over USB, but Android sees no player running, so the volume keys, ducking and Do Not Disturb rules can miss the music.

With it: music goes to the DAC over USB. A silent track plays on the phone’s own speaker, at volume zero, so Android sees music playing. The silent track never reaches the DAC.

What the track is, and is not

  • It cannot sound. It is mono, 16-bit zeros, looped, with its volume set to zero.
  • It cannot reach the DAC or another output. It is pinned to the phone’s own speaker. If Android ever routes it somewhere else, such as a USB device or a Bluetooth headset, it stops at once. If there is no speaker to pin it to, it is never started. The path to the DAC is not touched.
  • It costs next to nothing. It is tiny, on a low-power setting, with no thread of its own. It exists only while Direct plays, and is released when playback stops. The short rebuild at a change of sample rate does not recreate it.
  • It asks for nothing. It takes no audio focus, and it does not change what the media notification says.

Why we built it this way

We did not want to play real music through Android just to make it notice. That would put the Android route back in the middle. A silent track is the smallest thing that tells Android what it needs to know.

The cost is a tiny background job and a small extra thing to go wrong. We guarded it so that the worst case is nothing: every call that could fail is guarded, a failed start is only retried after a while, and the track cannot make a sound or move to the DAC. If it fails, playback goes on.

We found we needed it because of the volume keys. Other parts of Android also look for active music: volume-key routing, ducking, and Do Not Disturb rules. They would all otherwise see a phone that is silent.

For the curious

For the curiousThe numbers
  • The track is 8 kHz, mono, 16-bit, with a static 100 ms buffer that the platform loops. It is created in a power-saving mode.
  • When the USB stream is not running, the track stops after a short grace so that the rebuild of about 100 ms at a rate change does not recreate it.

Tested on HONOR LGN-NX3 with SNOWSKY Melody