Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions WooCommerce/Classes/POS/Utils/Audio/PointOfSaleSoundPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand All @@ -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)")
Expand Down
Loading