VLCPlayingExternallyView.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*****************************************************************************
  2. * VLCPlayingExternallyView.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <caro # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. import Foundation
  13. class VLCPlayingExternallyView: UIView {
  14. @IBOutlet weak var playingExternallyTitle: UILabel!
  15. @IBOutlet weak var playingExternallyDescription: UILabel!
  16. @objc var displayView: UIView? {
  17. return externalWindow?.rootViewController?.view
  18. }
  19. var externalWindow: UIWindow?
  20. @objc func shouldDisplay(_ show: Bool, movieView: UIView) {
  21. self.isHidden = !show
  22. if show {
  23. guard let screen = UIScreen.screens.count > 1 ? UIScreen.screens[1] : nil else {
  24. return
  25. }
  26. screen.overscanCompensation = .none
  27. externalWindow = UIWindow(frame: screen.bounds)
  28. guard let externalWindow = externalWindow else {
  29. return
  30. }
  31. externalWindow.rootViewController = VLCExternalDisplayController()
  32. externalWindow.rootViewController?.view.addSubview(movieView)
  33. externalWindow.screen = screen
  34. externalWindow.rootViewController?.view.frame = externalWindow.bounds
  35. movieView.frame = externalWindow.bounds
  36. } else {
  37. externalWindow = nil
  38. }
  39. externalWindow?.isHidden = !show
  40. }
  41. override func awakeFromNib() {
  42. playingExternallyTitle.text = NSLocalizedString("PLAYING_EXTERNALLY_TITLE", comment: "")
  43. playingExternallyDescription.text = NSLocalizedString("PLAYING_EXTERNALLY_DESC", comment:"")
  44. }
  45. @objc func updateUI(rendererItem: VLCRendererItem?) {
  46. if let rendererItem = rendererItem {
  47. playingExternallyTitle.text = NSLocalizedString("PLAYING_EXTERNALLY_TITLE_CHROMECAST", comment:"")
  48. playingExternallyDescription.text = rendererItem.name
  49. } else {
  50. playingExternallyTitle.text = NSLocalizedString("PLAYING_EXTERNALLY_TITLE", comment: "")
  51. playingExternallyDescription.text = NSLocalizedString("PLAYING_EXTERNALLY_DESC", comment:"")
  52. }
  53. }
  54. }