1

I use BMPlayer. When use func :

bmPlayerView.playTimeDidChange = { (currentTime: TimeInterval, totalTime: TimeInterval) in
            //            print("playTimeDidChange currentTime: \(currentTime) totalTime: \(totalTime)")
            self.subtitleShow(currentTime: currentTime)
        }

for show Subtitle in Label.

 func subtitleShow(currentTime: TimeInterval){

let millisecond = Int(currentTime * 1000)

                for i in (clip.subtitle?.enDialog)!{
                    if i.start <= millisecond && i.end >= millisecond {
                            subtitleLabel.text = i.text
                            return
                        }

                    }

            }

But Show Error:

enter image description here

Please help me

Mohammad Razipour
  • 3,643
  • 3
  • 29
  • 49

3 Answers3

1

The error message simply tells you to update the label on the main thread:

bmPlayerView.playTimeDidChange = { (currentTime: TimeInterval, totalTime: TimeInterval) in
    DispatchQueue.main.async {
       self.subtitleShow(currentTime: currentTime)
    }
}
vadian
  • 274,689
  • 30
  • 353
  • 361
1

If you want to change the UI, you must do it from the main thread. You can use this

bmPlayerView.playTimeDidChange = { (currentTime: TimeInterval, totalTime: TimeInterval) in
     // print("playTimeDidChange currentTime: \(currentTime) totalTime: \(totalTime)")
        dispatch_async(dispatch_get_main_queue()) { [weak self] () -> Void in
                    self?.subtitleShow(currentTime: currentTime)
        }

}
Witterquick
  • 6,048
  • 3
  • 26
  • 50
1

You cant modify gui from background. For do this you need use

DispatchQueue.main.async(){
    //code
}
Adrian Bobrowski
  • 2,681
  • 1
  • 16
  • 26