How QQ Music Mini‑Program Handles Audio Playback: Core Features, Bugs & Fixes
This article walks through the core functionalities of the QQ Music mini‑program—including station launch, friend cards, guided login, playback controls, lyric scrolling, dynamic background colors, and error handling—while sharing implementation details, common bugs on Android and iOS, and practical fixes for developers building audio features in WeChat mini‑apps.
Core Features of QQ Music Mini Program
Open station
Friend card
Guide page (prompt users to log in with WeChat to QQ Music or trigger cold start)
Cold start
Card details (friend similarity, preferences, comments )
Song playback page (play/pause, lyric scroll, favorite, track switch, playback reporting, background magic color, adaptation)
Mini player (track switch, state sync)
Core Feature Implementation
Audio State Synchronization
Playback state synchronization cannot use the
audiocomponent; instead it relies on WeChat native playback components. Navigating with
wx.navigateTo()keeps the current page alive, and returning triggers
onShow(not
onLoad), which is where state‑sync logic should run.
Song information and changes (playlist, play state, track switch, album art, title, artist, etc.) are stored in the Mini Program
storageto enable data sharing across pages.
Lyric Scrolling
The audio API lacks an
onTimeUpdateevent, so a timer is used to render scrolling lyrics, which is not perfectly precise. WeChat plans to add
onTimeUpdatesupport.
Background Color Magic
The app extracts a dominant hex color from the album cover, converts it to HSL, reduces saturation (S) and lightness (L) to soften the background, then converts it back to RGB.
Exception Handling
Handles missing or failed image loads, slow CGI responses in weak networks (shows loading spinner, hides after success, limits
wx.showToastto 10 s), and reports network or logic errors with device info for later debugging.
Music Playback Control Bugs & Fixes
Android pause‑then‑play issue
Older Android WeChat versions check
titleand
coverImgUrlwhen resuming; the bug was fixed by always passing these parameters.
iOS/Android pause‑then‑switch track
When pausing and then switching tracks, the old track may continue playing. The fix is to call
wx.stopBackgroundAudiobefore invoking
wx.playBackgroundAudio({dataUrl:'xxx'}).
Android sync playback state
When a song plays and a new page opens,
wx.getBackgroundAudioPlayerStatemay return status 2 (no music) and mismatched URLs. The solution is to store the playback URL in
storageand retrieve it for synchronization.
Mini Program Basics
Mina Framework
JS – logic layer development WXML – page layout WXSS – page styling
Logic Layer
The
App()function registers a Mini Program. Parameters are passed as an object defining lifecycle callbacks.
Data in
Pageis read‑only; updates must use
setData(), which performs a diff before rendering.
setDatapayload cannot exceed 1024 KB.
View Layer
The system consists of a view thread (renders WXML/WXSS) and an app service thread (runs JS). The JS thread runs in
jsCore, not in a WebView, so there is no global
windowobject.
Module System
Common code is extracted into separate JS files and exported via
module.exportsor
exports. Other files import them with
require(path).
WXSS
Introduces
rpxfor responsive layout (750 rpx = screen width). Images must be network URLs or base64 because local resources cannot be accessed directly.
API Highlights
wx.request sends HTTPS requests. Data is stringified if not already a string. Default
content-typeis
application/json; method names must be uppercase. Max concurrent requests: 5.
refereris fixed to
https://servicewechat.com/{appid}/{version}/page-frame.html. Timeout defaults to 60 s.
Music Playback
wx.getBackgroundAudioPlayerStateobtains playback status;
wx.playBackgroundAudioplays a single background track.
wx.pauseBackgroundAudiopauses,
wx.seekBackgroundAudioseeks, and
wx.stopBackgroundAudiostops (triggers
wx.onBackgroundAudioStop).
Data Caching
Mini Programs provide a local storage API (no cookies or sessionStorage). It supports asynchronous and synchronous CRUD operations.
Device Info
Use
wx.getSystemInfo()or
wx.getSystemInfoSync()to obtain device details for UI adaptation and error reporting.
UI Interaction
wx.showToast/
wx.hideToastfor brief messages,
wx.showModalfor dialogs. Navigation:
wx.navigateTokeeps the current page,
wx.navigateBackreturns;
wx.redirectToreplaces the current page. A Mini Program can keep up to five pages open simultaneously.
Authentication
wx.loginobtains a login code, which can be exchanged for
openidand
session_key.
wx.getUserInforetrieves user data after login.
Tencent IMWeb Frontend Team
IMWeb Frontend Community gathering frontend development enthusiasts. Follow us for refined live courses by top experts, cutting‑edge technical posts, and to sharpen your frontend skills.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.