Skip to content

Commit

Permalink
- Enhancement: "autoplay" media (video, audio) should automatically p…
Browse files Browse the repository at this point in the history
…lay #4658
  • Loading branch information
alvarotrigo committed Sep 26, 2024
1 parent a33817b commit a45ba73
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/js/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export function onMediaLoad(section){
// }
}

function hasAutoPlay(item){
return item.hasAttribute('data-autoplay') || item.hasAttribute('autoplay');
}

/**
* Plays video and audio elements.
Expand All @@ -28,20 +31,20 @@ export function playMedia(destiny){

//playing HTML5 media elements
utils.$('video, audio', panel).forEach(function(element){
if( element.hasAttribute('data-autoplay') && typeof element.play === 'function' ) {
if( hasAutoPlay(element) && typeof element.play === 'function' ) {
element.play();
}
});

//youtube videos
utils.$('iframe[src*="youtube.com/embed/"]', panel).forEach(function(element){
if ( element.hasAttribute('data-autoplay') ){
if ( hasAutoPlay(element) ){
playYoutube(element);
}

//in case the URL was not loaded yet. On page load we need time for the new URL (with the API string) to load.
element.onload = function() {
if ( element.hasAttribute('data-autoplay') ){
if ( hasAutoPlay(element) ){
playYoutube(element);
}
};
Expand Down

0 comments on commit a45ba73

Please sign in to comment.