From daff034b74bfc1209cc695031521add76fdd2610 Mon Sep 17 00:00:00 2001 From: Povilas Staskus <4062343+staskus@users.noreply.github.com> Date: Tue, 17 Jun 2025 23:18:57 +0300 Subject: [PATCH] Turn PointOfSaleSoundPlayer into actor to unblock the main thread --- .../POS/Utils/Audio/PointOfSaleSoundPlayer.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/WooCommerce/Classes/POS/Utils/Audio/PointOfSaleSoundPlayer.swift b/WooCommerce/Classes/POS/Utils/Audio/PointOfSaleSoundPlayer.swift index 86e099c70d5..09cbb008cbd 100644 --- a/WooCommerce/Classes/POS/Utils/Audio/PointOfSaleSoundPlayer.swift +++ b/WooCommerce/Classes/POS/Utils/Audio/PointOfSaleSoundPlayer.swift @@ -14,11 +14,9 @@ protocol PointOfSaleSoundPlayerProtocol { func playSound(_ sound: PointOfSaleSound) async } -final class PointOfSaleSoundPlayer: PointOfSaleSoundPlayerProtocol { - private var audioPlayer: AVAudioPlayer? +actor PointOfSaleSoundPlayer: PointOfSaleSoundPlayerProtocol { private var playerCache: [PointOfSaleSound: AVAudioPlayer] = [:] - @MainActor func playSound(_ sound: PointOfSaleSound) async { guard let url = Bundle.main.url(forResource: sound.name, withExtension: sound.type) else { DDLogError("Sound file not found: \(sound.name).\(sound.type)") @@ -34,9 +32,9 @@ final class PointOfSaleSoundPlayer: PointOfSaleSoundPlayerProtocol { } do { - audioPlayer = try AVAudioPlayer(contentsOf: url) - audioPlayer?.prepareToPlay() - audioPlayer?.play() + let audioPlayer = try AVAudioPlayer(contentsOf: url) + audioPlayer.prepareToPlay() + audioPlayer.play() playerCache[sound] = audioPlayer } catch { DDLogError("Failed to play sound: \(error)")