Skip to content

Commit daff034

Browse files
committed
Turn PointOfSaleSoundPlayer into actor to unblock the main thread
1 parent b6c2f01 commit daff034

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

WooCommerce/Classes/POS/Utils/Audio/PointOfSaleSoundPlayer.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ protocol PointOfSaleSoundPlayerProtocol {
1414
func playSound(_ sound: PointOfSaleSound) async
1515
}
1616

17-
final class PointOfSaleSoundPlayer: PointOfSaleSoundPlayerProtocol {
18-
private var audioPlayer: AVAudioPlayer?
17+
actor PointOfSaleSoundPlayer: PointOfSaleSoundPlayerProtocol {
1918
private var playerCache: [PointOfSaleSound: AVAudioPlayer] = [:]
2019

21-
@MainActor
2220
func playSound(_ sound: PointOfSaleSound) async {
2321
guard let url = Bundle.main.url(forResource: sound.name, withExtension: sound.type) else {
2422
DDLogError("Sound file not found: \(sound.name).\(sound.type)")
@@ -34,9 +32,9 @@ final class PointOfSaleSoundPlayer: PointOfSaleSoundPlayerProtocol {
3432
}
3533

3634
do {
37-
audioPlayer = try AVAudioPlayer(contentsOf: url)
38-
audioPlayer?.prepareToPlay()
39-
audioPlayer?.play()
35+
let audioPlayer = try AVAudioPlayer(contentsOf: url)
36+
audioPlayer.prepareToPlay()
37+
audioPlayer.play()
4038
playerCache[sound] = audioPlayer
4139
} catch {
4240
DDLogError("Failed to play sound: \(error)")

0 commit comments

Comments
 (0)