SoundPool does not play the audio.
Read the original article:SoundPool does not play the audio.
Problem Description
SoundPool does not play the audio.
Background Knowledge
SoundPool provides functionalities such as loading, playing, setting volume, looping, stopping playback, and unloading resources for short audio files. The SoundPool.unload method is used to unload audio that has already been loaded.
Problem Identification
Search for the keyword "SoundPool::Play" in the hilog logs to identify the audio ID played at the time the issue occurred. Record the audio ID and the playback time.
04-29 18:02:32.140 SoundPool::Play soundID::74,priority:0
Then search for the keyword "SoundPool::Unload soundID: audio ID" in the log to check the time when the audio was unloaded.
04-29 18:02:30.235 SoundPool::Unload soundID::74
Analysis Conclusion
If the audio unload time is earlier than the audio playback time, it indicates that the application unloaded the audio before the playback was completed, resulting in the audio not being played.
Suggestion for Modification
Listen to the ‘playFinished‘ event of SoundPool, and unload the audio in the callback function.
import { BusinessError } from '@kit.BasicServicesKit';
// Create a soundPool instance.
let soundPool: media.SoundPool;
let audioRendererInfo: audio.AudioRendererInfo = {
usage: audio.StreamUsage.STREAM_USAGE_MUSIC,
rendererFlags: 1
}
media.createSoundPool(5, audioRendererInfo, (error: BusinessError, soundPool_: media.SoundPool) => {
if (error) {
console.error(`Failed to createSoundPool`);
return;
} else {
soundPool = soundPool_;
console.info(`Succeeded in createSoundPool`);
soundPool.on('playFinished', () => {
console.info('Succeeded in playFinished');
// Execute the audio unload method here.
});
}
});
Written by Mehmet Karaaslan
HI-FI News
via DEV Community https://dev.to
October 17, 2025 at 05:15AM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€34.95 incl. VAT -
Easy Groove Super Set€199.00 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€34.95 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€45.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€35.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€34.95 incl. VAT








