قالب وردپرس درنا توس
Home / IOS Development / ios – Crash on UICollectionViewCell with JWVideoView – Swift

ios – Crash on UICollectionViewCell with JWVideoView – Swift



A ViewController has a UICollectionView . One of the cells contains JWVideoView . The app often crashes on PreparForReuse in this cell.

There is no valuable information in the log. So I'm having trouble figuring out the cause of the crash.

  import UIKit

class VideoArticleElementCollectionViewCell: UICollectionViewCell {

// NOTE: - Properties

public was imageURL: String? {didSet {videoView? .imageURL = imageURL}}
public was videoId: String? {didSet {videoView? .videoId = videoId}}

@IBOutlet private was videoView: JWVideoView?

// NOTE: - Reuse

override func PreparForReuse () {
super.prepareForReuse () // Crash here! (Thread 1
: EXC_BAD_ACCESS (code = 1, address = 0x7e8)) video view? .stopPlayingVideo () } deinit { video view? .stopPlayingVideo () } } import UIKit class JWVideoView: UIView, JWPlayerDelegate { // NOTE: Properties public was imageURL: String? public was videoId: String? {didSet {setupPlayer ()}} private was jwPlayer: JWPlayerController? private la jwPlayerURL = "https://content.jwplatform.com/manifests/" private var didPause = false // MARK: - Initialization override init (frame: CGRect) { super.init (frame: frame) setup () } convenience init () { self.init (frame: CGRect.zero) } required init? (codes aDecoder: NSCoder) { super.init (codes: aDecoder) setup () } // MARK: - Setup private funk setup () {} private func setupPlayer () { watch la videoId = self.videoId else {return} let playerURL = jwPlayerURL + videoId + ".m3u8" let configuration: JWConfig = JWConfig (contentURL: playerURL) config.controls = true configuration.autostart = true // configuration.premiumSkin = JWPremiumSkinGlow config.image = imageURL jwPlayer = JWPlayerController (config: configuration) if let player = jwPlayer { player.forceFullScreenOnLandscape = true player.forceLandscapeOnFullScreen = true player.view? .autoresizingMask = [.flexibleHeight, .flexibleWidth] player.view? .frame = borders player.delegate = self player.volume = 0.0 if let view = player.view {addSubview (view)} } } // MARK: - Orientation private funk enableAllOrientation (enable: Bool) { if let delegate = UIApplication.shared.delegate as? AppDelegate { // delegate.shouldEnableLandscape = enable } } // MARK: API public func stopPlayingVideo () { enableAllOrientation (enable: false) if jwPlayer! = null { jwPlayer! .stop () } } // MARK: - JWPlayerDelegate internal func onFullscreen (_ status: Bool) { if status == false { la value = UIInterfaceOrientation.portrait.rawValue UIDevice.current.setValue (value, for Key: "orientation") } } internal func onPlayAttempt () { if jwPlayer! = null { enableAllOrientation (enable: true) } } internal func onPlay (_ oldValue: String) { if did pause { didPause = false } } internal func onPause (_ oldValue: String) { didPause = true } internal func onComplete () { } }


Source link