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,540
  • 3
  • 28
  • 47

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
  • 253,546
  • 28
  • 306
  • 323
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
  • 5,973
  • 3
  • 25
  • 47
1

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

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