2017-02-07 10 views
2

動画を再生し、UIWebViewを使用してFirebaseのタイトルを表示しようとしています。私は2つのビューコントローラを持っています。最初の1つのvideoVCには、ビデオのラベルのcollectionViewがあります。タイトルを押すと、2番目のビューコントローラ "showVideosVC"に移動します。タイトルは正常に表示できますが、問題は私が空白のUIWebViewを得ることです。私はあなたがすると思います私のコレクションのViewクラスがUIWebViewを使用してサーバーから動画を再生していません

class videosVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{ 
    var posts = [Post]() 
    let db : DBHelperVideos = DBHelperVideos() 
    var arrayVideos = [videoModel]() 
    var selectedIndexPath : IndexPath = IndexPath() 
    var post: Post! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.arrayVideos.removeAll() 
     self.arrayVideos.append(contentsOf: self.db.fetchAll()) 
     self.collectionView.reloadData() 
     DataService.ds.REF_POSTS9.observe(.value, with: { (snapshot) in 

      if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] { 

       for snap in snapshot { 
        print ("SNAP: \(snap)”) 
        if let postDict = snap.value as? Dictionary<String, AnyObject>{ 
         let key = snap.key 
         let post = Post(postKey: key , postData: postDict) 
         self.posts.append(post) 
          self.db.insertBook(id: postDict["id"] as! String,bookName: postDict["video_name"] as! String, bookPath: "", bookURL: postDict["video_path"] as! String, caption: "")   
        } 
       } 
      } else { 

      } 
      self.arrayVideos.removeAll() 
      self.arrayVideos.append(contentsOf: self.db.fetchAll()) 
      self.collectionView.reloadData() 

     }) 

     collectionView.delegate = self 
     collectionView.dataSource = self 

    } 





    func getFilePath(name : String) -> String { 

     let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] 
     let filePath = documentsPath+"/"+name 
     return filePath 
    } 




    @IBAction func backbtn(_ sender: Any) { 
     if let navController = self.navigationController { 
      navController.popToRootViewController(animated: true) 
     } 
    } 



    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 

     return arrayVideos.count 
    } 




    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     let book = arrayVideos[indexPath.item] 
     if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)as? collectionViewCellVideos { 

      // cell.initWithBook(video: video) 

      cell.configureCell(video: video) 

      return cell 

     }else { 
      return collectionViewCellVideos() 
     } 
    } 

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
     self.selectedIndexPath = indexPath 
     self.performSegue(withIdentifier: "showVideo”, sender: self) 
    } 

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
    { 

     if segue.identifier == "showImage" 
     { 
      let vc = segue.destination as! showVideosVC 
      vc.video = self.arrayVideos[self.selectedIndexPath.row] 

     } 
    } 
} 

であり、これは動画

class showVideosVC: UIViewController , UIWebViewDelegate { 

    var video : videoModel? 

    @IBOutlet weak var webView: UIWebView! 


    override func viewDidLoad() { 
     super.viewDidLoad() 

     let url = NSURL(string: (book?.bookPath)!) 
     let url_request = NSURLRequest(url: url as! URL, 
             cachePolicy: NSURLRequest.CachePolicy.returnCacheDataElseLoad, 
             timeoutInterval: 20.0) 

     self.webView.loadRequest(url_request as URLRequest) 


    } 

} 

答えて

1

を果たすべき第二のクラスである私は、ビデオが、ここでプレイしていない理由を私が間違っているのか知っているか、いけません

let url_request = NSURLRequest(url: url as! URL,cachePolicy: NSURLRequest.CachePolicy.returnCacheDataElseLoad,timeoutInterval: 20.0) 
で、いくつかのデバッグに

の1-ブレークポイントをしなければなりません

を確認し、URLを確認して& Safariで開きます。

2-変更第二クラスにそれがエラー

class showVideosVC: UIViewController , UIWebViewDelegate { 

var video : videoModel? 

@IBOutlet weak var webView: UIWebView! 


override func viewDidLoad() { 
    super.viewDidLoad() 

    // Added 
    webView.delegate = self 

    let url = NSURL(string: (book?.bookPath)!) 
    let url_request = NSURLRequest(url: url as! URL, 
            cachePolicy: NSURLRequest.CachePolicy.returnCacheDataElseLoad, 
            timeoutInterval: 20.0) 

    self.webView.loadRequest(url_request as URLRequest) 


} 
// Added 
func webViewDidFinishLoad(_ webView: UIWebView) { 
    print("Loaded") 
} 
// Added 
func webView(_ webView: UIWebView, didFailLoadWithError error: Error) { 
    print("Error") 
} 


} 
でロードするかどうかを確認
関連する問題