Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SAPlayer) avoid shared instance #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kuamanet
Copy link

This is addressing the following:

Basically I've removed the shared instance and made the SAPlayer public. This allows whoever uses the library to play simultaneously more than one audio file. The caveat is that the AVAudioEngine must be created outside of the library.

let engine = AVAudioEngine()
let player1 = SAPlayer(engine: engine)
let player2 = SAPlayer(engine: engine)

I've played around with the demo, and everything seems to keep working as before.
I'm sorry for the big diff, I launched a swiftformat inside the project.

Only question, I commented the pause on the numberOfBuffersScheduledInTotal#didSet

private var numberOfBuffersScheduledInTotal = 0 {
        didSet {
            Log.debug("number of buffers scheduled in total: \(numberOfBuffersScheduledInTotal)")
            if numberOfBuffersScheduledInTotal == 0 {
                if playingStatus == .playing { wasPlaying = true }
                pause()
                // Pausing here triggers an odd state where, while downloading the audio the player will not resume playing when the first buffer is ready
//                pause()
                //                delegate?.didError()
                // TODO: we should not have an error here. We should instead have the throttler
                // propegate when it doesn't enough buffers while they were playing
                // TODO: "Make this a legitimate warning to user about needing more data from stream"
            }
            
            if numberOfBuffersScheduledInTotal > MIN_BUFFERS_TO_BE_PLAYABLE && wasPlaying {

            if numberOfBuffersScheduledInTotal > MIN_BUFFERS_TO_BE_PLAYABLE, wasPlaying {
                wasPlaying = false
                play()
            }
        }
    }

Nothing seems to change. What was that pause() guarding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant