-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vitaliy Salnikov
committed
Mar 25, 2024
1 parent
2799b8d
commit d73d492
Showing
1,930 changed files
with
1,823 additions
and
1,799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import UIKit | ||
import OVKit | ||
import AVFoundation | ||
|
||
class RotationsController: ViewController { | ||
|
||
private lazy var horizontalPlayerView: PlayerView = { | ||
let controls = InplaceCustomControls(frame: .zero) | ||
let player = PlayerView(frame: view.bounds, gravity: .fit, customControls: controls) | ||
player.delegate = self | ||
player.soundOn = true | ||
player.backgroundPlaybackPolicy = .continueAudioAndVideo | ||
return player | ||
}() | ||
|
||
|
||
private lazy var verticalPlayerView: PlayerView = { | ||
let controls = InplaceCustomControls(frame: .zero) | ||
let player = PlayerView(frame: view.bounds, gravity: .fit, customControls: controls) | ||
player.delegate = self | ||
player.soundOn = true | ||
player.backgroundPlaybackPolicy = .continueAudioAndVideo | ||
return player | ||
}() | ||
|
||
|
||
private lazy var controlledPlayerView: PlayerView = { | ||
horizontalPlayerView | ||
}() | ||
|
||
|
||
deinit { | ||
if isViewLoaded { | ||
horizontalPlayerView.stop() | ||
verticalPlayerView.stop() | ||
} | ||
} | ||
|
||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
navigationItem.title = "Rotations" | ||
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Switch player", style: .plain, target: self, action: #selector(tapSwitchPlayer)) | ||
|
||
view.addSubview(horizontalPlayerView) | ||
view.addSubview(verticalPlayerView) | ||
|
||
NotificationCenter.default.addObserver(self, selector: #selector(handleRotate), name: UIDevice.orientationDidChangeNotification, object: nil) | ||
|
||
loadVideo(Video(id: "-26006257_456245180"), for: horizontalPlayerView) | ||
loadVideo(Video(id: "-22822305_456242444"), for: verticalPlayerView) | ||
tapSwitch() | ||
} | ||
|
||
|
||
@objc func tapSwitch() { | ||
controlledPlayerView.autoRotateToLandscapeInFullscreenIfPossible.toggle() | ||
updateAutoRotateState() | ||
} | ||
|
||
|
||
func updateAutoRotateState() { | ||
let value = controlledPlayerView.autoRotateToLandscapeInFullscreenIfPossible | ||
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Auto: \(value)", style: .plain, target: self, action: #selector(tapSwitch)) | ||
highlightCurrentPlayer() | ||
} | ||
|
||
|
||
func highlightCurrentPlayer() { | ||
UIView.animate(withDuration: 0.2) { [controlledPlayerView] in | ||
controlledPlayerView.alpha = 0.2 | ||
} completion: { [controlledPlayerView] _ in | ||
UIView.animate(withDuration: 0.2) { | ||
controlledPlayerView.alpha = 1 | ||
} | ||
} | ||
} | ||
|
||
|
||
@objc func tapSwitchPlayer() { | ||
controlledPlayerView = controlledPlayerView == horizontalPlayerView ? verticalPlayerView : horizontalPlayerView | ||
updateAutoRotateState() | ||
} | ||
|
||
|
||
@objc func handleRotate() { | ||
guard PlayerView.canMaximizeToFullscreenInLandscape(from: self) else { return } | ||
controlledPlayerView.maximizeToFullscreenFromLandscapeOrientation() | ||
} | ||
|
||
|
||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { | ||
.portrait | ||
} | ||
|
||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
|
||
horizontalPlayerView.playerViewOnScreen = true | ||
verticalPlayerView.playerViewOnScreen = true | ||
} | ||
|
||
|
||
override func viewDidDisappear(_ animated: Bool) { | ||
super.viewDidDisappear(animated) | ||
|
||
horizontalPlayerView.playerViewOnScreen = false | ||
verticalPlayerView.playerViewOnScreen = false | ||
} | ||
|
||
|
||
override func viewDidLayoutSubviews() { | ||
super.viewDidLayoutSubviews() | ||
|
||
let safeFrame = view.bounds.inset(by: view.safeAreaInsets) | ||
var ratio = horizontalPlayerView.video?.size ?? .zero | ||
if ratio.width == 0 || ratio.height == 0 { | ||
ratio = CGSize(width: 16, height: 9) | ||
} | ||
|
||
let frame = AVMakeRect(aspectRatio: ratio, insideRect: safeFrame) | ||
.offsetBy(dx: 0, dy: -200) | ||
.inset(by: .init(top: 20, left: 20, bottom: 20, right: 50)) | ||
horizontalPlayerView.frame = AVMakeRect(aspectRatio: ratio, insideRect: frame) | ||
|
||
verticalPlayerView.frame = .init(x: 20, y: 400, width: 9*20, height: 16*20) | ||
verticalPlayerView.center.x = view.center.x + 80 | ||
} | ||
} | ||
|
||
|
||
class RotationsNavController: UINavigationController { | ||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { | ||
.portrait | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.