【问题标题】:Thread 5: Simultaneous accesses to 0x10b883638, but modification requires exclusive access线程5:同时访问0x10b883638,但修改需要独占访问
【发布时间】:2019-10-28 09:13:48
【问题描述】:

我已经询问了this question regarding some Apple 代码并使其工作。

我有looked here,但那里的答案并不能解决我的问题 虽然我解决了这个问题,但我没有在显示的行上收到以下错误。

线程5:同时访问0x10b883638,但修改需要独占访问

    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
    }
    ...

为什么会这样,我该如何解决?

【问题讨论】:

标签: ios swift avfoundation avplayeritem


【解决方案1】:

试试这个代码:

    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
        }

    }
}

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2019-01-11
    • 2018-03-07
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 2018-02-21
    • 2018-02-17
    • 1970-01-01
    • 2018-01-07
    相关资源
    最近更新 更多