0

I had asked this question regarding some Apple code and making it work.

I have looked here but the answer there does not solve my problem Although I solved that problem I am not getting the bellow error on the line shown.

Thread 5: Simultaneous accesses to 0x10b883638, but modification requires exclusive access

    private var playerItemContext = 0

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    // Only handle observations for the playerItemContext
    print("jdslfhjkfdhaldfahjkflhajfldashkjfdshkjlas")
    guard context == &playerItemContext else {
        super.observeValue(forKeyPath: keyPath, of: object,change: change, context: context)
        return
    }
    ...

Why is this and how can I fix this?

  • Possible duplicate of [Simultaneous accesses to 0x1c0a7f0f8, but modification requires exclusive access error on Xcode 9 beta 4](https://stackoverflow.com/questions/45415901/simultaneous-accesses-to-0x1c0a7f0f8-but-modification-requires-exclusive-access) – Xcoder Jun 13 '19 at 18:30
  • I have looked at that question and teh answer is old and does not fix my problem @Xcoder –  Jun 13 '19 at 18:30
  • Did you try this specific answer on that question? https://stackoverflow.com/a/47438532/243192 – Rengers Jun 13 '19 at 18:33
  • Yes, it did not change anything for me. @wvteijlingen –  Jun 13 '19 at 18:35

1 Answers1

0

Try this code:

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

    // Only handle observations for the playerItemContext
    guard context == &P2SheetViewController.playerStatusContext else {
        super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
        return
    }

    if keyPath == #keyPath(AVPlayer.status) {
        let status: AVPlayer.Status
        if let statusNumber = change?[.newKey] as? NSNumber {
            status = AVPlayer.Status(rawValue: statusNumber.intValue)!
        } else {
            status = .unknown
        }

        //Switch over status value
        switch status {
        case .readyToPlay:

            break
        // Player item is ready to play
        case .failed:
            print(".UKNOWN")

            break
        // Player item failed. See error.
        case .unknown:
            print(".UKNOWN")

            break
        // Player item is not yet ready.
        @unknown default: //new jul 17
            print(".UKNOWN")

            break
        }

    }
}

Hope it helps