In an HTML app on Android, bundle audio as MP3, AAC (M4A) or Ogg/Opus and video as MP4 (H.264 + AAC) or WebM, start playback from a user tap (or muted for video autoplay), unlock Web Audio on the first touch for games, and keep total media small — the free builder accepts 5 MB of zipped content and Pro 18 MB; larger media should stream from a server.
Key takeaways
- MP3 and MP4/H.264 play on every Android WebView.
- Start sound from a tap; muted video with
playsinlinecan autoplay. - Audio pauses when the app goes to the background.
- Media dominates APK size — compress hard or stream.
Formats that always work
| Type | Use | Notes |
|---|---|---|
| MP3 | Music, voice, effects | Universal; 96–128 kbps is plenty for voice |
| AAC / M4A | Music | Better quality per KB than MP3 |
| Ogg Opus | Voice, effects | Smallest files for speech |
| MP4 (H.264 + AAC) | Video | Hardware-decoded on every phone |
| WebM (VP9) | Video | Smaller; decoding support varies on older phones |
Autoplay rules
Like Chrome, a WebView can refuse to start sound that the user did not trigger. Reliable patterns:
<!-- background or hero video: muted autoplay is allowed -->
<video src="media/intro.mp4" autoplay muted loop playsinline poster="img/intro.jpg"></video>
<!-- sound: start from a tap -->
<button id="play">Play</button>
<script>
const a = new Audio('media/welcome.mp3');
play.onclick = () => a.play().catch(err => console.warn('blocked', err));
</script>Games: unlock Web Audio on first touch
const ctx = new (window.AudioContext || window.webkitAudioContext)();
addEventListener('pointerdown', function unlock() {
if (ctx.state === 'suspended') ctx.resume();
removeEventListener('pointerdown', unlock);
}, { once: true });Decode short effects once with ctx.decodeAudioData and replay the buffers — creating a new Audio element per shot causes lag on low-end phones. Most game engines (Phaser, PixiJS sound, Howler.js) do this for you.
Background and lock screen
When the user leaves the app or locks the phone, the WebView pauses, and playback stops. HTML apps are not suited to background music players or podcasts; use a native app for those. Pause your own media on visibilitychange so it resumes cleanly.
Keeping media small
- Voice: mono, 64 kbps Opus or 96 kbps MP3.
- Video: 720p is plenty on a phone; target 1–2 Mbps H.264. Ten seconds is about 2 MB.
- Over the size limit? Host the video on a server or video platform and stream it — it will need a connection.
Estimate before you build with how big an HTML APK is.
Frequently asked questions
Why doesn't my audio play in the app?
Playback was probably started without a user tap and blocked by autoplay rules, or the file path is absolute. Start audio from a click handler and use relative paths.
Can an HTML app play music in the background?
No. The WebView pauses when the app leaves the screen. Background playback needs a native media service.