NCViewerVideoToolBar.swift 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // NCViewerVideoToolBar.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/07/21.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. class NCViewerVideoToolBar: UIView {
  25. @IBOutlet weak var playButton: UIButton!
  26. @IBOutlet weak var muteButton: UIButton!
  27. var player: AVPlayer?
  28. override func willMove(toWindow newWindow: UIWindow?) {
  29. super.willMove(toWindow: newWindow)
  30. if newWindow != nil {
  31. let blurEffect = UIBlurEffect(style: .dark)
  32. let blurEffectView = UIVisualEffectView(effect: blurEffect)
  33. self.layer.cornerRadius = 15
  34. self.layer.masksToBounds = true
  35. blurEffectView.frame = self.bounds
  36. blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  37. self.insertSubview(blurEffectView, at:0)
  38. }
  39. }
  40. func setPlayer(player: AVPlayer?) {
  41. self.player = player
  42. }
  43. func setToolBar() {
  44. let mute = CCUtility.getAudioMute()
  45. if player?.rate == 1 {
  46. playButton.setImage(NCUtility.shared.loadImage(named: "pause.fill", color: .white), for: .normal)
  47. } else {
  48. playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .white), for: .normal)
  49. }
  50. if mute {
  51. muteButton.setImage(NCUtility.shared.loadImage(named: "audioOff", color: .white), for: .normal)
  52. } else {
  53. muteButton.setImage(NCUtility.shared.loadImage(named: "audioOn", color: .white), for: .normal)
  54. }
  55. }
  56. @IBAction func playerPause(_ sender: Any) {
  57. if player?.timeControlStatus == .playing {
  58. player?.pause()
  59. } else if player?.timeControlStatus == .paused {
  60. player?.play()
  61. }
  62. }
  63. @IBAction func setMute(_ sender: Any) {
  64. let mute = CCUtility.getAudioMute()
  65. CCUtility.setAudioMute(!mute)
  66. player?.isMuted = !mute
  67. setToolBar()
  68. }
  69. }