123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- //
- // StudyDetailViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/5/13.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class StudyDetailViewController: BaseViewController, WKNavigationDelegate {
- @IBOutlet weak var btnPlay: UIButton!
- @IBOutlet weak var btnGuanZhu: UIButton!
- @IBOutlet weak var lblCount: UILabel!
- @IBOutlet weak var lblDate: UILabel!
- @IBOutlet weak var lblTitle: UILabel!
- @IBOutlet weak var webContentView: UIView!
- @IBOutlet weak var viewContent: UIView!
- @IBOutlet weak var viewVideo: UIView!
- @IBOutlet weak var viewTop: UIView!
- @IBOutlet weak var scrollView: UIScrollView!
- var wkWebView: WKWebView!
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "在线学习"
- initNavLeftBackButton()
- viewVideo.setSizeHeight(height: ScreenWidth / 375 * 213)
- viewVideo.setSizeWidth(width: ScreenWidth)
- btnGuanZhu.setCornerRadius(size: 6)
- viewContent.marginTop(top: 0, view: viewVideo)
- viewTop.setSizeHeight(height: viewContent.bottom())
- webContentView.marginTop(top: 0, view: viewTop)
- scrollView.contentSize.height = webContentView.bottom()
- lblTitle.text = getString(key: "title")
- let config = WKWebViewConfiguration.init()
- wkWebView = WKWebView.init(frame: webContentView.bounds, configuration: config)
- wkWebView.navigationDelegate = self
- self.webContentView.addSubview(wkWebView)
- let count = "\(getIntValue(key: "click_num"))+"
- lblCount.attributedText = CommonViewUntils.getAttributedString(str: "\(count)人学过", left: 0, right: count.length() + 1, color: CommonUntils.getUIColorFromRGB(rgbValue: 0xffb400, alpha: 1.0), otherColor: CommonUntils.getUIColorFromRGB(rgbValue: 0x999999, alpha: 1.0))
- btnPlay.setCenterForSuperView()
- viewVideo.bringSubviewToFront(btnPlay)
- lblDate.text = getString(key: "creaetime")
- initPlay()
- loadData()
- }
- func initPlay() {
- let controlView = ZFPlayerControlView()
- controlView.fastViewAnimated = true
- controlView.autoHiddenTimeInterval = 5
- controlView.autoFadeTimeInterval = 0.5
- controlView.prepareShowLoading = true
- let playManager = ZFAVPlayerManager()
- vcPlayer = ZFPlayerController(playerManager: playManager, containerView: viewVideo)
- vcPlayer.controlView = controlView
- //后台继续 播放
- vcPlayer.pauseWhenAppResignActive = false
- vcPlayer.orientationWillChange = {[weak self] (player, isFullScreen) in
- self!.setNeedsStatusBarAppearanceUpdate()
- }
- ///播放完成
- vcPlayer.playerDidToEnd = {[weak self] (asset) in
- self!.vcPlayer.currentPlayerManager.stop?()
- }
- vcPlayer.customAudioSession = true
- vcPlayer.playerReadyToPlay = { (asse, url) in
- do {
- try AVAudioSession.sharedInstance().setCategory(.playback, options: .allowBluetooth)
- try AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation)
- } catch {}
- }
- }
- var vcPlayer: ZFPlayerController!
- func playView(url: String) {
- vcPlayer.assetURLs = [URL(string: url)!]
- //vcPlayer.playTheIndex(0);
- }
- func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
- var webheight = 0.0
- // 获取内容实际高度
- self.wkWebView.evaluateJavaScript("document.body.scrollHeight") { [unowned self] (result, _) in
- if let tempHeight: Double = result as? Double {
- webheight = tempHeight
- print("webheight: \(webheight)")
- }
- DispatchQueue.main.async { [unowned self] in
- self.webContentView.setSizeHeight(height: CGFloat(webheight))
- self.wkWebView.setSizeHeight(height: CGFloat(webheight))
- self.scrollView.contentSize.height = self.webContentView.bottom()
- }
- }
- }
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 播放 暂停
- self.vcPlayer.playTheIndex(0)
- break
- case 1002: // 关注
- uploadGZ()
- break
- case 1003: //
- break
- case 1004: //
- break
- case 1005: //
- break
- case 1006: //
- break
- default:
- break
- }
- }
- // MARK: =============加载数据===============
- func loadData() {
- let url = RequestURL.onlineDetail
- let params = NSMutableDictionary()
- params.setValue(getString(key: "id"), forKey: "id")
- loadDataInfo(url: url, params: params, tag: 1001)
- }
- func uploadGZ() {
- let url = RequestURL.startStudy
- let params = NSMutableDictionary()
- params.setValue(getString(key: "id"), forKey: "id")
- submitData(url: url, params: params, tag: 1002)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- let onlineDetail = dicData["onlineDetail"] as! NSDictionary
- dicData.setDic(dic: onlineDetail)
- playView(url: getString(key: "video_url"))
- let isFlow = getIntValue(key: "isFlow")
- lblDate.text = getString(key: "creaetime")
- wkWebView.loadDataForUrl(url: getString(key: "webUrl"))
- if isFlow == 1 {
- btnGuanZhu.setTitle("已关注", for: .normal)
- btnGuanZhu.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xcccccc, alpha: 1.0)
- btnGuanZhu.isEnabled = false
- } else {
- btnGuanZhu.setTitle("关注", for: .normal)
- btnGuanZhu.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xfcb400, alpha: 1.0)
- }
- } else if tag == 1002 {
- btnGuanZhu.setTitle("已关注", for: .normal)
- btnGuanZhu.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xcccccc, alpha: 1.0)
- }
- }
- override func returnError(tag: Int, type: String) {
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- if self.vcPlayer != nil {
- self.vcPlayer.isViewControllerDisappear = false
- }
- }
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- if self.vcPlayer != nil {
- self.vcPlayer.isViewControllerDisappear = true
- }
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "StudyDetailViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|