Skip to content

Not able to show thumbnails of youtube links.  #77

Description

@sarathdev

Not able to show thumbnails of youtube links. We had a discussion about the same issue for showing for youtube links that are starting with "m.youtube.com". Now what is happening is if we copy a link from youtube player the link what we are getting is entirely different from all the previous links what we handling.
Adding the code that I'm using to show the URL embedded view below

if sosFeedPostDesc.extractURLs() is URL{
                if  let extractedUrls = sosFeedPostDesc.extractURLs() {
                    let url: URL
                    if (extractedUrls as AnyObject).host?.contains("m.youtube.com") == true {
                        var components = URLComponents(string: (extractedUrls as AnyObject).absoluteString as! String)
                        components?.host = "www.youtube.com"
                        if let _url = components?.url {
                            url = _url
                        } else {
                            url = extractedUrls as! URL
                        }
                    } else {
                        url = extractedUrls as! URL
                    }
                    
                    cell.urlPreviewViewHeightConstraint.constant = 60
                    print("Exrtracted URL: \(url.absoluteString) Index:\(indexPath.row)")
                    
                    let embeddedView = URLEmbeddedView()
                    //                    embeddedView.loadURL(url.absoluteString)
                    embeddedView.load(urlString: url.absoluteString)
                    embeddedView.borderColor = .clear
                    embeddedView.cornerRaidus = 0
                    embeddedView.frame = CGRect(x: 0, y:0, width: cell.frame.width - 20, height: 60)
                    embeddedView.didTapHandler = { [weak self] _, url in
                        guard let url = url else { return }
                        self?.present(SFSafariViewController(url: url), animated: true, completion: nil)
                    }
                    for view in cell.urlEmbededViewOutlet.subviews {
                        if let ev = view as? URLEmbeddedView {
                            ev.cancelLoading()
                            ev.removeFromSuperview()
                        }
                    }
                    
                    cell.urlEmbededViewOutlet.addSubview(embeddedView)
                    
                }
            }
            else{
                for view in cell.urlEmbededViewOutlet.subviews {
                    if let ev = view as? URLEmbeddedView {
                        ev.cancelLoading()
                        ev.removeFromSuperview()
                    }
                }
                cell.urlPreviewViewHeightConstraint.constant = 0
            }

Added the entire code in the descrition. Please suggest if you found any edits in existing code as well. Waiting for to hear from you. Thanks in advance :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions