How to properly load a video from a url into a WebView

I have a URL stored in my database that plays a video for a product. I have successfully parsed my JSON so that I have my URL being pulled from my Model. I don't have any errors but my WebView is also blank. I am not sure if my method is working correctly with my Web Kit View. I have found little to no information on how to find a solution for this process in OS X. Any help would be greatly appreciated.


import Cocoa
import WebKit
class ProductDetail: NSViewController {
    @IBOutlet weak var mainVideo: WebView!
   
    var buildProductDetail: ProductModel? {
       
        didSet{
           
        setupAppVideo()
           
        }
       
    }
    override func viewDidLoad() {
        super.viewDidLoad()
       
    }
   
    func setupAppVideo(){
       
        if let appVideoURL = buildProductDetail?.product_video {
           
            let url = NSURL(string: appVideoURL)
           
            URLSession.shared.dataTask(with: url! as URL,completionHandler:{(data,response,error) in
               
                if error != nil {
                    print(error)
                    return
                }
               
                self.mainVideo.webPlugInMainResourceDidReceive(data!)
               
               
               
            }).resume()
           
        }
    }
}

Replies

So I think I have gotten a little further but I am still unsure how to load my data from my session into my WebView. My first method that sets up my App Icon works perfectly. The methoid that sets up my video works when i hardcode the URL but obviously I want it to be dynamic based off which collectionView Item has been clicked. How do I assign my data from my completion handler to my video much like I am with my image?


func setupAppIconImage() {
       
        if let appIconImageURL = buildProduct?.product_image {
            let url = NSURL(string: appIconImageURL)
           
            URLSession.shared.dataTask(with: url! as URL,completionHandler:{(data, response, error) in
               
                if error != nil {
                    print(error)
                    return
                }
               
                self.productImageView.image = NSImage(data: data!)
               
            }).resume()
           
        }
       
    }
   
    func setupAppVideo(){
       
       
        if let appVideoURL = buildProduct?.product_video{
           
            let url = NSURL(string: appVideoURL)
           
            /
           
            URLSession.shared.dataTask(with: url! as URL,completionHandler:{(data,response,error) in
               
                if error != nil {
                    print(error)
                    return
                }
               
                let request = NSURLRequest(url: url as! URL)
               
                self.videoTemp.mainFrame.load(request as URLRequest!)
               
            }).resume()
           
        }
    }