-
Notifications
You must be signed in to change notification settings - Fork 894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ads] Fix NTT video background may be blank after changing NTP media type setting #25285
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -257,7 +257,18 @@ class NewTabPageViewController: UIViewController { | |
} | ||
|
||
background.changed = { [weak self] in | ||
self?.setupBackgroundImage() | ||
guard let self else { return } | ||
setupBackgroundImage() | ||
|
||
let isTabVisible = viewIfLoaded?.window != nil | ||
setupBackgroundVideoIfNeeded(shouldCreatePlayer: isTabVisible) | ||
// Load the video asset here, as viewDidAppear is not called when the view | ||
// is already visible | ||
if isTabVisible { | ||
videoPlayer?.loadAndAutoplayVideoAssetIfNeeded( | ||
shouldAutoplay: false | ||
) | ||
} | ||
} | ||
|
||
Preferences.BraveNews.isEnabled.observe(from: self) | ||
|
@@ -330,7 +341,7 @@ class NewTabPageViewController: UIViewController { | |
} | ||
|
||
setupBackgroundImage() | ||
setupBackgroundVideoIfNeeded() | ||
setupBackgroundVideoIfNeeded(shouldCreatePlayer: true) | ||
backgroundView.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
|
@@ -394,7 +405,6 @@ class NewTabPageViewController: UIViewController { | |
self?.reportSponsoredBackgroundEvent(.viewedImpression) | ||
} | ||
|
||
setupBackgroundVideoIfNeeded() | ||
videoPlayer?.loadAndAutoplayVideoAssetIfNeeded( | ||
shouldAutoplay: shouldShowBackgroundVideo() | ||
) | ||
|
@@ -487,20 +497,22 @@ class NewTabPageViewController: UIViewController { | |
) | ||
} | ||
|
||
func setupBackgroundVideoIfNeeded() { | ||
func setupBackgroundVideoIfNeeded(shouldCreatePlayer: Bool) { | ||
videoButtonsView.isHidden = true | ||
|
||
// Setup the background video only if: | ||
// - it hasn't been setup before | ||
// - the current NTP background is a video | ||
guard videoPlayer == nil, | ||
let backgroundVideoPath = background.backgroundVideoPath | ||
else { | ||
guard let backgroundVideoPath = background.backgroundVideoPath else { | ||
videoPlayer = nil | ||
backgroundView.resetPlayerLayer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to free resources and hide play button when the current NTP is changed from NTT video to image background. |
||
backgroundButtonsView.resetVideoBackgroundButtons() | ||
return | ||
} | ||
|
||
gradientView.isHidden = false | ||
videoPlayer = NewTabPageVideoPlayer(backgroundVideoPath) | ||
if shouldCreatePlayer { | ||
videoPlayer?.createPlayer() | ||
} | ||
|
||
backgroundView.setupPlayerLayer(backgroundVideoPath, player: videoPlayer?.player) | ||
|
||
videoButtonsView.tappedBackgroundVideo = { [weak videoPlayer] in | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a proper place to call
setupBackgroundVideoIfNeeded
after background is changed (which happens when user changesNew Tab Page
setting)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to create AVPlayer object only if current tab is visible to avoid memory/processor consumption.
AVPlayer object will be created during
willMove(...)
when user switches to tab.