Skip to content

Commit

Permalink
refactor hakimel#3078
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel authored and stefanocampanella committed Mar 1, 2022
1 parent 90de862 commit eea9443
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions js/controllers/slidecontent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { HORIZONTAL_SLIDES_SELECTOR, VERTICAL_SLIDES_SELECTOR } from '../utils/constants.js'
import { extend, queryAll, closest } from '../utils/util.js'
import { extend, queryAll, closest, getMimeTypeFromFile } from '../utils/util.js'
import { isMobile } from '../utils/device.js'

import fitty from 'fitty';
Expand Down Expand Up @@ -137,7 +136,13 @@ export default class SlideContent {

// Support comma separated lists of video sources
backgroundVideo.split( ',' ).forEach( source => {
video.innerHTML += '<source src="'+ source +'" type="video/' + source.split(".").pop() + '">';
let type = getMimeTypeFromFile( source );
if( type ) {
video.innerHTML += `<source src="${source}" type="${type}">`;
}
else {
video.innerHTML += `<source src="${source}">`;
}
} );

backgroundContent.appendChild( video );
Expand Down
15 changes: 15 additions & 0 deletions js/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,19 @@ export const getRemainingHeight = ( element, height = 0 ) => {

return height;

}

const fileExtensionToMimeMap = {
'mp4': 'video/mp4',
'm4a': 'video/mp4',
'ogv': 'video/ogg',
'mpeg': 'video/mpeg',
'webm': 'video/webm'
}

/**
* Guess the MIME type for common file formats.
*/
export const getMimeTypeFromFile = ( filename='' ) => {
return fileExtensionToMimeMap[filename.split('.').pop()]
}

0 comments on commit eea9443

Please sign in to comment.