-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Autoplay detection library: initial release && Teads Bid Adapter: detect autoplay #11222
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ea1ac1
Add autoplay library
github-matthieu-wipliez 3444b39
Filter out bids with needAutoplay if autoplay is disabled
github-matthieu-wipliez 3c57a77
Refactoring + add test
github-matthieu-wipliez 98b6fba
Simplify logic for filtering bids
github-matthieu-wipliez ed3427c
Start detection in autoplay.js directly
github-matthieu-wipliez 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
let autoplayEnabled = null; | ||
|
||
/** | ||
* Note: this function returns true if detection is not done yet. This is by design: if autoplay is not allowed, | ||
* the call to video.play() will fail immediately, otherwise it may not terminate. | ||
* @returns true if autoplay is not forbidden | ||
*/ | ||
export const isAutoplayEnabled = () => autoplayEnabled !== false; | ||
|
||
// generated with: | ||
// ask ChatGPT for a 160x90 black PNG image (1/8th the size of 720p) | ||
// | ||
// encode with: | ||
// ffmpeg -i black_image_160x90.png -r 1 -c:v libx264 -bsf:v 'filter_units=remove_types=6' -pix_fmt yuv420p autoplay.mp4 | ||
// this creates a 1 second long, 1 fps YUV 4:2:0 video encoded with H.264 without encoder details. | ||
// | ||
// followed by: | ||
// echo "data:video/mp4;base64,$(base64 -i autoplay.mp4)" | ||
|
||
const autoplayVideoUrl = | ||
'data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wN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pbHN0AAAAJal0b28AAAAdZGF0YQAAAAEAAAAATGF2ZjYwLjE2LjEwMA=='; | ||
|
||
function startDetection() { | ||
// we create an HTMLVideoElement muted and not displayed in which we try to play a one frame video | ||
const videoElement = document.createElement('video'); | ||
videoElement.src = autoplayVideoUrl; | ||
videoElement.setAttribute('playsinline', 'true'); | ||
videoElement.muted = true; | ||
|
||
videoElement | ||
.play() | ||
.then(() => { | ||
autoplayEnabled = true; | ||
videoElement.pause(); | ||
}) | ||
.catch(() => { | ||
autoplayEnabled = false; | ||
}); | ||
} | ||
|
||
// starts detection as soon as this library is loaded | ||
startDetection(); |
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
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.
much happier this worked than sourcing an external file