Receiving NIL where known values exists

I’m working on an app where a user can view a video inside the app. The video is store on the server with the link in MySQL, the information is being parsed. I attempted to hard code a link into the player and it definitely works. The issue is the value is coming back NIL when I go through the actual code. Any help is greatly appreciated.

 

// Load Videos

    func loadVideo() {
        /
            let id = guest["id"]!
         
            /
            let url = URL(string: "http:/
         
            /
            var request = URLRequest(url: url)
         
            /
            request.httpMethod = "POST"
         
            /
            let body = "id=(id)&text=&uuid="
            request.httpBody = body.data(using: String.Encoding.utf8)
         
            /
            URLSession.shared.dataTask(with: request) { data, response, error in
             
                /
                DispatchQueue.main.async(execute: {
                 
                    /
                    if error == nil {
                     
                        do {
                         
                            /
                            let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
                         
                            /
                            self.tweets.removeAll(keepingCapacity: false)
                        
                            /
                            guard let parseJSON = json else {
                                print("Error while parsing")
                                return
                            }
                         
                            /
                            guard let posts = parseJSON["posts"] as? [String:AnyObject] else {
                                print("Error while parseJSONing")
                                return
                            }
                         
                         
                            /
                            self.tweets = posts
                         
                         
                            /
                            /
                             
                                /
                                let path = self.tweets["path"]
                            print(path as! [String:AnyObject])
                                /
                                if !path!.isEmpty {
                                    let url = URL(string: path! as! String)! /
                                    let videourl = try? Data(contentsOf: url) /
                                    /
                                }
                             
                            /
                     
                         
                        } catch {
                            /
                            DispatchQueue.main.async(execute: {
                                let message = "(error)"
                                appDelegate.infoView(message: message, color: colorSmoothRed)
                            })
                            return
                        }
                     
                    } else {
                        /
                        DispatchQueue.main.async(execute: {
                            let message = error!.localizedDescription
                            appDelegate.infoView(message: message, color: colorSmoothRed)
                        })
                        return
                    }
                 
                })
             
                }.resume()

        }

// Play Video
    @IBAction func playVideo(_ sender: Any) {
        loadVideo()
        print("video", videourl)
        print("self", self.tweets["path"] as Any)
        let avPlayerController = AVPlayerViewController()
        avPlayerController.player = AVPlayer.init(url: URL.init(string: videourl)!)
        avPlayerController.player?.play()
        present(avPlayerController, animated: true, completion: nil)
    }

 

// PHP Code



    // STEP 2.1 Pass POST / GET via html encrypt and assign passed id of user to $id var
    $id = htmlentities($_REQUEST["id"]);




    // STEP 2.2 Select posts + user related to $id
    $posts = $access->selectVideos($id);


    // STEP 2.3 If posts are found, append them to $returnArray
    if (!empty($posts)) {
        $returnArray["posts"] = $posts;
   

Powered by WPeMatico

About

You may also like...

Comments are closed.