VLCPlayingExternallyView.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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) {
  21. self.isHidden = !show
  22. externalWindow?.isHidden = !show
  23. if show {
  24. guard let screen = UIScreen.screens.count > 1 ? UIScreen.screens[1] : nil else {
  25. return
  26. }
  27. screen.overscanCompensation = .none
  28. externalWindow = UIWindow(frame: screen.bounds)
  29. guard let externalWindow = externalWindow else {
  30. return
  31. }
  32. externalWindow.rootViewController = VLCExternalDisplayController()
  33. externalWindow.screen = screen
  34. externalWindow.rootViewController?.view.frame = externalWindow.bounds
  35. } else {
  36. externalWindow = nil
  37. }
  38. }
  39. override func awakeFromNib() {
  40. playingExternallyTitle.text = NSLocalizedString("PLAYING_EXTERNALLY_TITLE", comment: "")
  41. playingExternallyDescription.text = NSLocalizedString("PLAYING_EXTERNALLY_DESC", comment:"")
  42. }
  43. @objc func updateUI(rendererItem: VLCRendererItem?) {
  44. if let rendererItem = rendererItem {
  45. playingExternallyTitle.text = NSLocalizedString("PLAYING_EXTERNALLY_TITLE_CHROMECAST", comment:"")
  46. playingExternallyDescription.text = rendererItem.name
  47. } else {
  48. playingExternallyTitle.text = NSLocalizedString("PLAYING_EXTERNALLY_TITLE", comment: "")
  49. playingExternallyDescription.text = NSLocalizedString("PLAYING_EXTERNALLY_DESC", comment:"")
  50. }
  51. }
  52. }