From d782389d7447723d36012aeabe0f4c4e442449a2 Mon Sep 17 00:00:00 2001 From: Muhammad Umer Date: Sat, 11 Nov 2023 22:42:27 +0500 Subject: [PATCH] chore: add chromecast to app-nav --- Source/ChromeCastButtonDelegate.swift | 67 +++--------- Source/ChromeCastManager.swift | 103 +++--------------- Source/ChromeCastMetaDataModel.swift | 4 +- Source/ContainerNavigationController.swift | 8 -- Source/CourseContentPageViewController.swift | 3 +- Source/CourseDashboardHeaderView.swift | 59 +++++++++- Source/CourseDashboardViewController.swift | 2 +- .../CutomePlayer/ChromeCastMiniPlayer.swift | 11 +- Source/CutomePlayer/VideoPlayerControls.swift | 22 +++- Source/EnrolledTabBarViewController.swift | 2 +- Source/NewCourseDashboardViewController.swift | 1 + Source/OEXAppDelegate.m | 4 +- Source/VideoBlockViewController.swift | 31 +----- edX.xcodeproj/project.pbxproj | 2 +- 14 files changed, 134 insertions(+), 185 deletions(-) diff --git a/Source/ChromeCastButtonDelegate.swift b/Source/ChromeCastButtonDelegate.swift index 72dde2219b..08a29eb26e 100644 --- a/Source/ChromeCastButtonDelegate.swift +++ b/Source/ChromeCastButtonDelegate.swift @@ -9,70 +9,39 @@ import Foundation import GoogleCast -/// Chrome cast button will always be added to the index one in case of more than one right navbar items -let ChromeCastButtonIndex = 1 - -/// Handles chrome cast button addition and removal from the navigation bar -/// This protocol will handle button addition/removal to navigation bar without consedering the video cast state protocol ChromeCastButtonDelegate { var chromeCastButton: GCKUICastButton { get } - var chromeCastButtonItem: UIBarButtonItem { get } - func addChromeCastButton() + func addChromeCastButton(tintColor: UIColor?) func removeChromecastButton() } -/// Handles chrome cast button addition and removal from the navigation bar -/// This protocol will handle button addition/removal to navigation bar when the video is being casted: connected state -protocol ChromeCastConnectedButtonDelegate: ChromeCastButtonDelegate { -} - -/// Default implementation of Protocol ChromeCastButtonDelegate, -/// This way Controller just needs to add 'ChromeCastButtonDelegate' and it will have all desired functionality -extension ChromeCastButtonDelegate where Self: UIViewController { - /// Provides Reference to ChromeCastButton that will be added to Navigationbar +class ChromecastEnableView: UIView, ChromeCastButtonDelegate { + private var buttonSize: CGFloat = 24 + var chromeCastButton: GCKUICastButton { - let castButton = GCKUICastButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24)) - castButton.tintColor = OEXStyles.shared().primaryBaseColor() + let castButton = GCKUICastButton(frame: CGRect(x: 0, y: 0, width: buttonSize, height: buttonSize)) castButton.oex_addAction({ _ in ChromeCastManager.shared.viewExpanded = true }, for: .touchUpInside) return castButton } - var chromeCastButtonItem: UIBarButtonItem { - return UIBarButtonItem(customView: chromeCastButton) - } - - func addChromeCastButton() { - guard let count = navigationItem.rightBarButtonItems?.count, count >= 1 else { - navigationItem.rightBarButtonItem = chromeCastButtonItem - return + func addChromeCastButton(tintColor: UIColor? = nil) { + let castButton = chromeCastButton + if let tintColor = tintColor { + castButton.tintColor = tintColor } - - var isAdded = false - navigationItem.rightBarButtonItems?.forEach({ item in - if item.customView is GCKUICastButton { - isAdded = true - return - } - }) - - if isAdded { return } - - navigationItem.rightBarButtonItems?.insert(chromeCastButtonItem, at: ChromeCastButtonIndex) + addSubview(castButton) + castButton.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + castButton.centerXAnchor.constraint(equalTo: centerXAnchor), + castButton.centerYAnchor.constraint(equalTo: centerYAnchor), + castButton.widthAnchor.constraint(equalToConstant: buttonSize), + castButton.heightAnchor.constraint(equalToConstant: buttonSize) + ]) } func removeChromecastButton() { - guard let navigationBarItems = navigationItem.rightBarButtonItems else { - navigationItem.rightBarButtonItem = nil - return - } - - for (index, element) in navigationBarItems.enumerated() { - if element.customView is GCKUICastButton { - navigationItem.rightBarButtonItems?.remove(at: index) - break - } - } + subviews.first(where: { $0 is GCKUICastButton })?.removeFromSuperview() } } diff --git a/Source/ChromeCastManager.swift b/Source/ChromeCastManager.swift index 84b32796a9..c03408ca7c 100644 --- a/Source/ChromeCastManager.swift +++ b/Source/ChromeCastManager.swift @@ -49,6 +49,14 @@ private enum DelegateCallbackType: Int { return sessionManager?.hasConnectedCastSession() ?? false } + var isAvailable: Bool { + return discoveryManager?.deviceCount ?? 0 > 0 + } + + var currentPlayingVideoCourseID: String? { + return sessionManager?.currentCastSession?.remoteMediaClient?.mediaStatus?.mediaInformation?.metadata?.string(forKey: ChromeCastCourseID) + } + private var callbackType: DelegateCallbackType = .none { didSet { if oldValue != callbackType { @@ -84,9 +92,8 @@ private enum DelegateCallbackType: Int { } func add(delegate: ChromeCastPlayerStatusDelegate) { - let conteins = delegates.filter { $0 === delegate } - if conteins.count > 0 { return } - + let contains = delegates.filter { $0 === delegate } + if contains.count > 0 { return } delegates.append(delegate) } @@ -107,21 +114,6 @@ private enum DelegateCallbackType: Int { currentSession.remoteMediaClient?.remove(self) } - func showIntroductoryOverlay(items: [UIBarButtonItem]) { - guard let button = items.first else { return } - guard let view = button.customView as? GCKUICastButton, !view.isHidden else { return } - context.presentCastInstructionsViewControllerOnce(with: view) - } - - //MARK:- GCKSessionManager methods - func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKSession) { - DispatchQueue.main.async { [weak self] in - self?.addMediaListner() - self?.addChromeCastButton() - self?.callbackType = .connect - } - } - private func delegateCallBacks() { for delegate in delegates { switch callbackType { @@ -170,11 +162,18 @@ private enum DelegateCallbackType: Int { environment?.interface?.sendAnalyticsEvents(state, withCurrentTime: streamPosition, forVideo: video, playMedium: AnalyticsEventDataKey.PlayMediumChromecast.rawValue) } + //MARK:- GCKSessionManager methods + func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKSession) { + DispatchQueue.main.async { [weak self] in + self?.addMediaListner() + self?.callbackType = .connect + } + } + func sessionManager(_ sessionManager: GCKSessionManager, didEnd session: GCKSession, withError error: Error?) { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in self?.removeMediaListener() self?.callbackType = .disconnect - self?.removeChromeCastButton() } } @@ -206,70 +205,4 @@ private enum DelegateCallbackType: Int { break } } - - //MARK:- ChromeCastButtonDelegate methods - private func addChromeCastButton() { - let topViewcontroller = UIApplication.shared.topMostController() - guard let navController = topViewcontroller?.navigationController as? ForwardingNavigationController else { return } - - navController.viewControllers.forEach { [weak self] controller in - self?.addChromeCastButton(over: controller) - } - } - - func addChromeCastButton(over controller: UIViewController) { - guard let controller = controller as? ChromeCastButtonDelegate else { return } - - if controller is ChromeCastConnectedButtonDelegate { - if isConnected { - controller.addChromeCastButton() - } - } - else { - controller.addChromeCastButton() - } - } - - private func removeChromeCastButton() { - let topViewcontroller = UIApplication.shared.topMostController() - guard let navController = topViewcontroller?.navigationController as? ForwardingNavigationController else { return } - - navController.viewControllers.forEach { [weak self] controller in - self?.removeChromeCastButton(from: controller) - } - } - - func removeChromeCastButton(from controller: UIViewController, force: Bool = false) { - guard let controller = controller as? ChromeCastButtonDelegate else { return } - - if force { - controller.removeChromecastButton() - return - } - - if controller is ChromeCastConnectedButtonDelegate { - controller.removeChromecastButton() - } - } - - func handleCastButton(for controller: UIViewController) { - guard let _ = controller as? ChromeCastButtonDelegate else { return } - // Delay of 4 seconds is added as it takes framework to - // initialize and return true if it has already established connection - let delay: Double = isInitilized ? 0 : 4 - - if !isInitilized { - DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in - if !(self?.isInitilized ?? true) && self?.isConnected ?? false { - // Add media listner if video is being casted, ideally chromecast SDK shuold configure it automatically but unfortunately, its not configuring media listener. So adding media listner manually - self?.addMediaListner() - } - self?.isInitilized = true - self?.addChromeCastButton(over: controller) - } - } - else { - addChromeCastButton(over: controller) - } - } } diff --git a/Source/ChromeCastMetaDataModel.swift b/Source/ChromeCastMetaDataModel.swift index 2bdb022596..cf527f5637 100644 --- a/Source/ChromeCastMetaDataModel.swift +++ b/Source/ChromeCastMetaDataModel.swift @@ -10,13 +10,15 @@ import Foundation import GoogleCast let ChromeCastVideoID = "ChromeCastVideoID" +let ChromeCastCourseID = "ChromeCastCourseID" /// Extension of GCKMediaInformation to allow building of media information with meta data to be provided to chrome cast Device extension GCKMediaInformation { - static func buildMediaInformation(contentID: String, title: String, videoID: String, contentType: ChromeCastContentType, streamType: GCKMediaStreamType, thumbnailUrl: String?, deviceName: String?) -> GCKMediaInformation { + static func buildMediaInformation(courseID: String, contentID: String, title: String, videoID: String, contentType: ChromeCastContentType, streamType: GCKMediaStreamType, thumbnailUrl: String?, deviceName: String?) -> GCKMediaInformation { let metadata = GCKMediaMetadata(metadataType: .movie) metadata.setString(title, forKey: kGCKMetadataKeyTitle) metadata.setString(deviceName ?? "", forKey: kGCKMetadataKeyStudio) + metadata.setString(courseID, forKey: ChromeCastCourseID) metadata.setString(videoID, forKey: ChromeCastVideoID) if let thumbnailUrl = thumbnailUrl, let url = URL(string: thumbnailUrl) { diff --git a/Source/ContainerNavigationController.swift b/Source/ContainerNavigationController.swift index 09712bea10..d5c30c9269 100644 --- a/Source/ContainerNavigationController.swift +++ b/Source/ContainerNavigationController.swift @@ -183,11 +183,3 @@ extension UINavigationController { coordinator.animate(alongsideTransition: nil) { _ in completion?() } } } - -extension ForwardingNavigationController { - override func pushViewController(_ viewController: UIViewController, animated: Bool) { - super.pushViewController(viewController, animated: animated) - - ChromeCastManager.shared.handleCastButton(for: viewController) - } -} diff --git a/Source/CourseContentPageViewController.swift b/Source/CourseContentPageViewController.swift index 1da0c37233..49fb1e9152 100644 --- a/Source/CourseContentPageViewController.swift +++ b/Source/CourseContentPageViewController.swift @@ -22,7 +22,7 @@ extension CourseBlockDisplayType { } // Container for scrolling horizontally between different screens of course content -public class CourseContentPageViewController : UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate, CourseBlockViewController, InterfaceOrientationOverriding, ChromeCastButtonDelegate { +public class CourseContentPageViewController : UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate, CourseBlockViewController, InterfaceOrientationOverriding { public typealias Environment = OEXAnalyticsProvider & DataManagerProvider & OEXRouterProvider & OEXConfigProvider @@ -122,7 +122,6 @@ public class CourseContentPageViewController : UIPageViewController, UIPageViewC } addObservers() addRestrictedViewToPagination() - ChromeCastManager.shared.removeChromeCastButton(from: self, force: true) } // This is to restrict the pagination for bottom bar of player to make player progress slider smooth diff --git a/Source/CourseDashboardHeaderView.swift b/Source/CourseDashboardHeaderView.swift index d17d1091ea..3ca4a7a13f 100644 --- a/Source/CourseDashboardHeaderView.swift +++ b/Source/CourseDashboardHeaderView.swift @@ -91,6 +91,8 @@ class CourseDashboardHeaderView: UIView { return button }() + private lazy var chromercastView = ChromecastEnableView() + private lazy var certificateView: CourseCertificateView? = nil private func addCertificateView() { @@ -185,6 +187,12 @@ class CourseDashboardHeaderView: UIView { // it will be used to hide value prop from header in favor of embeded value prop on course dashboard private var hideValueProp: Bool = false + private var chromeCastManager = ChromeCastManager.shared + + private var isChromeCastConnected: Bool { + return chromeCastManager.isConnected && chromeCastManager.currentPlayingVideoCourseID == course?.course_id + } + init(environment: Environment, course: OEXCourse?, tabbarItems: [TabBarItem], error: CourseAccessHelper?) { self.environment = environment self.course = course @@ -195,6 +203,8 @@ class CourseDashboardHeaderView: UIView { addSubViews() setOrUpdateConstraints() configureView() + + ChromeCastManager.shared.add(delegate: self) } private func configureView() { @@ -234,6 +244,23 @@ class CourseDashboardHeaderView: UIView { make.edges.equalTo(self) } + if isChromeCastConnected { + if !containerView.subviews.contains(chromercastView) { + containerView.addSubview(chromercastView) + } + + chromercastView.addChromeCastButton(tintColor: environment.styles.neutralWhiteT()) + + chromercastView.snp.remakeConstraints { make in + make.top.equalTo(containerView).offset(StandardVerticalMargin * 2) + make.trailing.equalTo(closeButton.snp.leading).offset(-StandardHorizontalMargin) + make.height.equalTo(imageSize) + make.width.equalTo(imageSize) + } + } else { + chromercastView.removeFromSuperview() + } + closeButton.snp.remakeConstraints { make in make.top.equalTo(containerView).offset(StandardVerticalMargin * 2) make.trailing.equalTo(containerView).inset(StandardVerticalMargin * 2) @@ -245,7 +272,7 @@ class CourseDashboardHeaderView: UIView { make.top.equalTo(closeButton) make.centerY.equalTo(closeButton) make.leading.equalTo(containerView).offset(StandardHorizontalMargin) - make.trailing.equalTo(closeButton.snp.leading).offset(-StandardHorizontalMargin) + make.trailing.equalTo(isChromeCastConnected ? chromercastView.snp.leading : closeButton.snp.leading).offset(-StandardHorizontalMargin) } if state == .collapsed { return } @@ -391,6 +418,10 @@ class CourseDashboardHeaderView: UIView { hideValueProp = hide setOrUpdateConstraints() } + + func reset() { + chromeCastManager.remove(delegate: self) + } } extension CourseDashboardHeaderView: CourseDashboardTabbarViewDelegate { @@ -398,3 +429,29 @@ extension CourseDashboardHeaderView: CourseDashboardTabbarViewDelegate { delegate?.didTapTabbarItem(at: position, tabbarItem: tabbarItem) } } + +extension CourseDashboardHeaderView: ChromeCastPlayerStatusDelegate { + func chromeCastDidConnect() { + guard let course = course else { return } + let currentPlayingCourseID = chromeCastManager.currentPlayingVideoCourseID + if currentPlayingCourseID == course.course_id { + setOrUpdateConstraints() + } + } + + func chromeCastDidDisconnect(playedTime: TimeInterval) { + setOrUpdateConstraints() + } + + func chromeCastVideoPlaying() { + guard let course = course else { return } + let currentPlayingCourseID = chromeCastManager.currentPlayingVideoCourseID + if currentPlayingCourseID == course.course_id { + setOrUpdateConstraints() + } + } + + func chromeCastDidFinishPlaying() { + + } +} diff --git a/Source/CourseDashboardViewController.swift b/Source/CourseDashboardViewController.swift index 969eae1841..7e67fa78a7 100644 --- a/Source/CourseDashboardViewController.swift +++ b/Source/CourseDashboardViewController.swift @@ -8,7 +8,7 @@ import UIKit -class CourseDashboardViewController: UITabBarController, InterfaceOrientationOverriding, ChromeCastConnectedButtonDelegate { +class CourseDashboardViewController: UITabBarController, InterfaceOrientationOverriding { typealias Environment = OEXAnalyticsProvider & OEXConfigProvider & DataManagerProvider & NetworkManagerProvider & OEXRouterProvider & OEXInterfaceProvider & ReachabilityProvider & OEXSessionProvider & OEXStylesProvider & RemoteConfigProvider & ServerConfigProvider diff --git a/Source/CutomePlayer/ChromeCastMiniPlayer.swift b/Source/CutomePlayer/ChromeCastMiniPlayer.swift index 084288b060..0ead35197d 100644 --- a/Source/CutomePlayer/ChromeCastMiniPlayer.swift +++ b/Source/CutomePlayer/ChromeCastMiniPlayer.swift @@ -63,13 +63,14 @@ class ChromeCastMiniPlayer: UIViewController { func play(video: OEXHelperVideoDownload, time: TimeInterval) { guard let videoURL = video.summary?.videoURL, - let url = URL(string: videoURL), - let videoID = video.summary?.videoID else { + let courseID = video.course_id, + let url = URL(string: videoURL), + let videoID = video.summary?.videoID else { return } self.video = video let thumbnail = video.summary?.videoThumbnailURL ?? courseImageURLString - let mediaInfo = mediaInformation(contentID: url.absoluteString, title: video.summary?.name ?? "", videoID: videoID, contentType: contentType(url: url.absoluteString), streamType: .buffered, thumbnailUrl: thumbnail) + let mediaInfo = mediaInformation(courseID: courseID, contentID: url.absoluteString, title: video.summary?.name ?? "", videoID: videoID, contentType: contentType(url: url.absoluteString), streamType: .buffered, thumbnailUrl: thumbnail) play(with: mediaInfo, at: time) { success in if success { @@ -119,10 +120,10 @@ class ChromeCastMiniPlayer: UIViewController { viewController.didMove(toParent: self) } - private func mediaInformation(contentID: String, title: String, videoID: String, contentType: ChromeCastContentType, streamType: GCKMediaStreamType, thumbnailUrl: String?) -> GCKMediaInformation { + private func mediaInformation(courseID: String, contentID: String, title: String, videoID: String, contentType: ChromeCastContentType, streamType: GCKMediaStreamType, thumbnailUrl: String?) -> GCKMediaInformation { let deviceName = ChromeCastManager.shared.sessionManager?.currentCastSession?.device.friendlyName - return GCKMediaInformation.buildMediaInformation(contentID: contentID, title: title, videoID: videoID, contentType: contentType, streamType: streamType, thumbnailUrl: thumbnailUrl, deviceName: deviceName) + return GCKMediaInformation.buildMediaInformation(courseID: courseID, contentID: contentID, title: title, videoID: videoID, contentType: contentType, streamType: streamType, thumbnailUrl: thumbnailUrl, deviceName: deviceName) } private func play(with mediaInfo: GCKMediaInformation, at time: TimeInterval, completion: ChromeCastItemCompletion? = nil) { diff --git a/Source/CutomePlayer/VideoPlayerControls.swift b/Source/CutomePlayer/VideoPlayerControls.swift index abfd08457f..a8b5061818 100644 --- a/Source/CutomePlayer/VideoPlayerControls.swift +++ b/Source/CutomePlayer/VideoPlayerControls.swift @@ -46,7 +46,7 @@ class VideoPlayerControls: UIView, VideoPlayerSettingsDelegate, UIGestureRecogni private let previousButtonSize = CGSize(width: 42.0, height: 42.0) private let rewindButtonSize = CGSize(width: 42.0, height: 42.0) private let durationSliderHeight: CGFloat = 34.0 - private let timeRemainingLabelSize = CGSize(width: 80, height: 34.0) + private let timeRemainingLabelSize = CGSize(width: 60, height: 34.0) private let settingButtonSize = CGSize(width: 24.0, height: 24.0) private let fullScreenButtonSize = CGSize(width: 20.0, height: 20.0) private let tableSettingSize = CGSize(width: 110.0, height: 100.0) @@ -254,6 +254,8 @@ class VideoPlayerControls: UIView, VideoPlayerSettingsDelegate, UIGestureRecogni return label }() + private lazy var chromercastView = ChromecastEnableView() + private var barColor: UIColor { return UIColor.black.withAlphaComponent(0.7) } @@ -262,6 +264,8 @@ class VideoPlayerControls: UIView, VideoPlayerSettingsDelegate, UIGestureRecogni return bottomBar.frame } + private let chromecastManager = ChromeCastManager.shared + init(environment : Environment, player: VideoPlayer) { self.environment = environment videoPlayer = player @@ -427,8 +431,22 @@ class VideoPlayerControls: UIView, VideoPlayerSettingsDelegate, UIGestureRecogni make.height.equalTo(timeRemainingLabelSize.height) } + if chromecastManager.isAvailable { + bottomBar.addSubview(chromercastView) + + chromercastView.snp.makeConstraints { make in + make.leading.equalTo(timeRemainingLabel.snp.trailing).offset(StandardVerticalMargin) + make.height.equalTo(settingButtonSize.height) + make.width.equalTo(settingButtonSize.width) + make.centerY.equalTo(bottomBar.snp.centerY) + } + + chromercastView.addChromeCastButton(tintColor: environment.styles.neutralWhiteT()) + } + btnSettings.snp.makeConstraints { make in - make.leading.equalTo(timeRemainingLabel.snp.trailing).offset(StandardVerticalMargin) + let leadingAnchor = chromecastManager.isAvailable ? chromercastView.snp.trailing : timeRemainingLabel.snp.trailing + make.leading.equalTo(leadingAnchor).offset(StandardVerticalMargin) make.height.equalTo(settingButtonSize.height) make.width.equalTo(settingButtonSize.width) make.centerY.equalTo(bottomBar.snp.centerY) diff --git a/Source/EnrolledTabBarViewController.swift b/Source/EnrolledTabBarViewController.swift index f69ed16bc0..bf52242d65 100644 --- a/Source/EnrolledTabBarViewController.swift +++ b/Source/EnrolledTabBarViewController.swift @@ -26,7 +26,7 @@ private enum TabBarOptions: Int { } } -class EnrolledTabBarViewController: UITabBarController, InterfaceOrientationOverriding, ChromeCastConnectedButtonDelegate { +class EnrolledTabBarViewController: UITabBarController, InterfaceOrientationOverriding { typealias Environment = OEXAnalyticsProvider & OEXConfigProvider & DataManagerProvider & NetworkManagerProvider & OEXRouterProvider & OEXInterfaceProvider & ReachabilityProvider & OEXSessionProvider & OEXStylesProvider & ServerConfigProvider diff --git a/Source/NewCourseDashboardViewController.swift b/Source/NewCourseDashboardViewController.swift index 6b25f53c42..7ba0f6a1b8 100644 --- a/Source/NewCourseDashboardViewController.swift +++ b/Source/NewCourseDashboardViewController.swift @@ -392,6 +392,7 @@ extension NewCourseDashboardViewController: CourseDashboardHeaderViewDelegate { } func didTapOnClose() { + headerView.reset() dismiss(animated: true) } diff --git a/Source/OEXAppDelegate.m b/Source/OEXAppDelegate.m index 2823ff90cf..7f26f0bfba 100644 --- a/Source/OEXAppDelegate.m +++ b/Source/OEXAppDelegate.m @@ -255,8 +255,8 @@ - (void)setupGlobalEnvironment :(NSDictionary *) launchOptions { [NewRelicAgent enableCrashReporting:NO]; [NewRelicAgent startWithApplicationToken:newrelic.apiKey]; } - // Disable for app nav release -// [self initilizeChromeCast]; + + [self initilizeChromeCast]; } - (void) initilizeChromeCast { diff --git a/Source/VideoBlockViewController.swift b/Source/VideoBlockViewController.swift index f27b19e043..c6f653e807 100644 --- a/Source/VideoBlockViewController.swift +++ b/Source/VideoBlockViewController.swift @@ -167,7 +167,6 @@ class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewCo } chromeCastManager.remove(delegate: self) removeOverlayMessage() - removeChromeCastButton() chromeCastMiniPlayer = nil } @@ -178,6 +177,10 @@ class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewCo } videoTranscriptView?.invalidateTimer() videoTranscriptView = nil + + chromeCastMiniPlayer = nil + chromeCastManager.remove(delegate: self) + videoPlayer.removeControls() } override func viewDidAppear(_ animated : Bool) { @@ -199,11 +202,6 @@ class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewCo if !chromeCastManager.isConnected && videoTranscriptView?.transcripts.count ?? 0 > 0 { validateSubtitleTimer() } - - if !(video?.summary?.isYoutubeVideo ?? true) { - addChromeCastButton() - showChromeCastOverlay() - } } override func viewDidDisappear(_ animated: Bool) { @@ -211,16 +209,6 @@ class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewCo subtitleTimer.invalidate() } - private func addChromeCastButton() { - guard let parent = parent else { return } - chromeCastManager.addChromeCastButton(over: parent) - } - - private func removeChromeCastButton() { - guard let parent = parent else { return } - chromeCastManager.removeChromeCastButton(from: parent, force: true) - } - func setAccessibility() { if let ratingController = presentedViewController as? RatingViewController, UIAccessibility.isVoiceOverRunning { // If Timely App Reviews popup is showing then set popup elements as accessibilityElements @@ -555,17 +543,6 @@ class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewCo //MARK:- ChromeCastHelper - private func showChromeCastOverlay() { - // Introductory overlay needs reference to castButton which is available in CourseContentPageViewController, - // This function calls before the castButton is initialized so we get x, y as 0 in its container, - // We put a delay of 2 sec to get castButton from navigationbar item then decouple it and assgin to call. - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [weak self] in - guard let parentController = self?.parent as? CourseContentPageViewController, - let items = parentController.navigationItem.rightBarButtonItems else { return } - self?.chromeCastManager.showIntroductoryOverlay(items: items) - } - } - private func addOverly(with message: String) { if overlayLabel != nil { return } removeOverlayPlayButton() diff --git a/edX.xcodeproj/project.pbxproj b/edX.xcodeproj/project.pbxproj index 74243de625..d95a84bb2b 100644 --- a/edX.xcodeproj/project.pbxproj +++ b/edX.xcodeproj/project.pbxproj @@ -4162,12 +4162,12 @@ BECB7B071924C0C3009C77F1 /* Sources */, BECB7B081924C0C3009C77F1 /* Frameworks */, BECB7B091924C0C3009C77F1 /* Resources */, - 77BDD65E1A44BD7300EA2A9C /* Process Config */, 77E647AC1C90C10400B6740D /* Embed Frameworks */, E0D9C59723FEAE100085218B /* Remove Unsupported Architectures */, E094D55D2474E8150071BAAD /* Firebase Crashlytics */, BFD74E97BAF89D19434811E5 /* [CP] Embed Pods Frameworks */, 43A92E60C5A96043835CC691 /* [CP] Copy Pods Resources */, + 77BDD65E1A44BD7300EA2A9C /* Process Config */, ); buildRules = ( );