Skip to content

Commit

Permalink
Version 2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Salnikov committed Mar 25, 2024
1 parent 2799b8d commit d73d492
Show file tree
Hide file tree
Showing 1,930 changed files with 1,823 additions and 1,799 deletions.
24 changes: 18 additions & 6 deletions Demo/PlayerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
1306CD7FF4EB5A9F13229912 /* VKVideoPlayer in Frameworks */ = {isa = PBXBuildFile; productRef = 55904406B78EC8E5D1E3C4C6 /* VKVideoPlayer */; };
37045C262B692515000A8AC9 /* RotationsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37045C252B692515000A8AC9 /* RotationsController.swift */; };
D40B0A2A2AA5EB7A009EDEA8 /* FullscreenCustomControls.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40B0A292AA5EB7A009EDEA8 /* FullscreenCustomControls.swift */; };
D421DB7A2A264DFF002C86E0 /* ImportSourceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D421DB792A264DFF002C86E0 /* ImportSourceView.swift */; };
D43BD367257E244B007952B6 /* ImportController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D43BD366257E244B007952B6 /* ImportController.swift */; };
Expand Down Expand Up @@ -61,6 +62,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
37045C252B692515000A8AC9 /* RotationsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RotationsController.swift; sourceTree = "<group>"; };
B11EC48D2620C75A00B063FA /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
D40B0A292AA5EB7A009EDEA8 /* FullscreenCustomControls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullscreenCustomControls.swift; sourceTree = "<group>"; };
D421DB792A264DFF002C86E0 /* ImportSourceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportSourceView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -117,6 +119,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
37045C242B6924F6000A8AC9 /* Rotations */ = {
isa = PBXGroup;
children = (
37045C252B692515000A8AC9 /* RotationsController.swift */,
);
path = Rotations;
sourceTree = "<group>";
};
D4027CC82B2A0D6C00DC65E8 /* Controls */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -154,6 +164,7 @@
D4CA48392575B331009C5DB3 /* Single */,
EA480D6327B2AF8200EDDD24 /* Detail */,
D4CA48382575B327009C5DB3 /* Feed */,
37045C242B6924F6000A8AC9 /* Rotations */,
D4CA47E82575A267009C5DB3 /* AppDelegate.swift */,
D4BD26C929D7201A005C52C6 /* SceneDelegate.swift */,
D4CA47F12575A268009C5DB3 /* Assets.xcassets */,
Expand Down Expand Up @@ -308,7 +319,7 @@
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1510;
LastUpgradeCheck = 1500;
TargetAttributes = {
D4CA47E42575A267009C5DB3 = {
CreatedOnToolsVersion = 12.2;
Expand Down Expand Up @@ -386,6 +397,7 @@
D4D425292A9CFED2002A16E5 /* PiPCustomControls.swift in Sources */,
EADF7211274D11C300FAD363 /* DownloadsCollectionCell.swift in Sources */,
EAD174812AE7FC60008E34E7 /* FeedControlsView.swift in Sources */,
37045C262B692515000A8AC9 /* RotationsController.swift in Sources */,
EA480D6727B2CA4E00EDDD24 /* PlayerViewProvider.swift in Sources */,
EA1656B526BD6F1B007743EE /* FocusOfInterestTracker.swift in Sources */,
D4CA483C2575B3B0009C5DB3 /* FeedController.swift in Sources */,
Expand Down Expand Up @@ -543,7 +555,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1.84.2;
CURRENT_PROJECT_VERSION = 2.5;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
Expand All @@ -552,7 +564,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.84.2;
MARKETING_VERSION = 2.5;
PRODUCT_BUNDLE_IDENTIFIER = com.onevideo.player.demo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -568,7 +580,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1.84.2;
CURRENT_PROJECT_VERSION = 2.5;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
Expand All @@ -577,7 +589,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.84.2;
MARKETING_VERSION = 2.5;
PRODUCT_BUNDLE_IDENTIFIER = com.onevideo.player.demo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -614,7 +626,7 @@
repositoryURL = "https://github.com/VKCOM/VideoPlayer-iOS";
requirement = {
kind = exactVersion;
version = 1.84.2;
version = 2.5.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
55 changes: 2 additions & 53 deletions Demo/PlayerDemo/Common/Controls/FullscreenCustomControls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,13 @@ import OVKit
class FullscreenCustomControls: UIView, PlayerFullscreenControlsViewProtocol {

// MARK: - PlayerFullscreenControlsViewProtocol

var enableBottomControls: Bool = true


var splitMode: Bool = false

var alwaysShowSoundButton: Bool = false

var keyboardOverlapsBottomView: Bool = false

var keepVisible: Bool = false

var onVisibilityChange: VoidBlock?

var customSafeInsets: UIEdgeInsets? = nil

var customControlInsets: (() -> UIEdgeInsets)?

var customBottomShadowInset: (() -> CGFloat)?

var customBottomShadowHeight: ((UITraitCollection) -> CGFloat?)?

var controlsDidLayout: (() -> Void)?

weak var customViewsContainer: UIView?

var bottomControlsFrame: CGRect {
.zero
}

func togglePause() {
handlePlayPauseButton()
}
Expand All @@ -46,30 +24,9 @@ class FullscreenCustomControls: UIView, PlayerFullscreenControlsViewProtocol {

func fastSeekToStart() {
}


// MARK: - ClosableControls

var hideCloseButton: Bool = false {
didSet {
guard hideCloseButton != oldValue else { return }
closeButton?.isHidden = isHidden || hideCloseButton
}
}

weak var closeButton: UIButton? {
didSet {
closeButton?.isHidden = isHidden || controlMask == nil || hideCloseButton
closeButton?.alpha = controlsVisible ? 1 : 0
}
}

weak var pipButton: UIButton? {
didSet {
pipButton?.isHidden = true
}
func keyboardOverlapHeightChanged(to height: CGFloat) {
}


// MARK: - HideableControls

Expand Down Expand Up @@ -168,20 +125,12 @@ class FullscreenCustomControls: UIView, PlayerFullscreenControlsViewProtocol {
super.layoutSubviews()

playPauseButton.center = CGPoint(x: bounds.midX, y: bounds.midY)
controlsDidLayout?()
}

override var isHidden: Bool {
didSet {
closeButton?.isHidden = isHidden || hideCloseButton
}
}

func updateControlsVisible(visible: Bool, animated: Bool) {
let alpha: CGFloat = visible ? 1 : 0
let update = {
self.playPauseButton.alpha = alpha
self.closeButton?.alpha = self.splitMode ? 1.0 : alpha
}
if animated {
UIView.animate(withDuration: 0.24, delay: 0, options: .curveEaseInOut, animations: {
Expand Down
5 changes: 4 additions & 1 deletion Demo/PlayerDemo/Common/TabbarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class TabbarController: UITabBarController {
let downloads = NavigationController(rootViewController: DownloadsController())
downloads.tabBarItem = UITabBarItem(title: "Downloads", image: UIImage(systemName: "arrow.down.to.line"), selectedImage: nil)

viewControllers = [single, feed, transitions, multiplay, downloads]
let rotations = RotationsNavController(rootViewController: RotationsController())
rotations.tabBarItem = UITabBarItem(title: "Rotations", image: UIImage(systemName: "rotate.left"), selectedImage: nil)

viewControllers = [single, feed, transitions, multiplay, downloads, rotations]
}


Expand Down
138 changes: 138 additions & 0 deletions Demo/PlayerDemo/Rotations/RotationsController.swift
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
}
}
17 changes: 11 additions & 6 deletions Demo/PlayerDemo/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ extension SceneDelegate: PlayerManagerDelegate {
return Self.findTopViewController(base: window!.rootViewController)
}

func customPiPControls(with frame: CGRect) -> UIView {
func pictureInPictureControls(with frame: CGRect) -> UIView? {
return PiPCustomControls(frame: frame)
}


func fullscreenControls(for video: VideoType?, originPlayerView: PlayerView?) -> UIView? {
return FullscreenCustomControls(frame: .zero)
}

func playerView(_ fromPlayerView: OVKit.PlayerView, willShowPiP pip: OVKit.PiPWindow) {
}


func playerView(_ fromPlayerView: OVKit.PlayerView?, willShowFullscreen fullscreenController: OVKit.FullscreenContentController) -> OVKit.FullscreenController? {
func playerView(_ fromPlayerView: OVKit.PlayerView?, willShowFullscreen fullscreenController: OVKit.FullscreenContentViewController) -> OVKit.FullscreenController? {
// Принудительное включение звука
fromPlayerView?.soundOn = true
fullscreenController.alwaysShowSoundButton = true

// Полноэкранный плеер можно показать сразу с supplementary view controller
if fromPlayerView?.demo_context?.openWithDetail == true, let video = (fromPlayerView ?? fullscreenController.playerView).video {
Expand Down Expand Up @@ -90,10 +93,12 @@ extension SceneDelegate: PlayerManagerDelegate {


extension SceneDelegate {

class func findTopViewController(base: UIViewController?) -> UIViewController? {
if let nav = base as? UINavigationController {
return findTopViewController(base: nav.visibleViewController)
if let visible = nav.visibleViewController {
return findTopViewController(base: visible)
}
}
if let tab = base as? UITabBarController {
if let selected = tab.selectedViewController {
Expand Down
Loading

0 comments on commit d73d492

Please sign in to comment.