Source: media/player/VideoPlayerUtils.js

import { VectorGraphics } from "./VectorGraphics.js"
export { VideoPlayerUtils }

/**
 * Static class with video related utilities.
 * @author ckraemme <ckraemme@awi.de>
 */
class VideoPlayerUtils {
    /**
     * Get the data url of the video player poster based on the hostname.
     */
    static getPoster() {
        const hostname = window.location.hostname;
        const whiteColor = '#f2f2f2';
        const backgroundColor = '#0000';
        let posterUrl = undefined;
        if (hostname.includes('marine-data'))
            posterUrl = VectorGraphics.marineDataLogo(whiteColor, whiteColor, backgroundColor);
        else if (hostname.includes('earth-data'))
            posterUrl = VectorGraphics.earthDataLogo(whiteColor, whiteColor, backgroundColor);
        else if (hostname.includes('o2a-data'))
            posterUrl = VectorGraphics.o2aDataLogo(whiteColor, whiteColor, backgroundColor, backgroundColor);
        else
            posterUrl = VectorGraphics.o2aDataLogo(whiteColor, whiteColor, backgroundColor, backgroundColor);
        return posterUrl
    }

    /**
     * Get the MIME type based on file extension.
     * @see https://docs.videojs.com/utils_mimetypes.js.html
     * @param {string} filepath 
     * @returns MIME type
     */
    static getMimeType(filepath) {

        if (!filepath)
            return ''

        const mimeTypeCollection = {
            opus: 'video/ogg',
            ogv: 'video/ogg',
            mp4: 'video/mp4',
            mov: 'video/mp4',
            m4v: 'video/mp4',
            mkv: 'video/x-matroska',
            m4a: 'audio/mp4',
            mp3: 'audio/mpeg',
            aac: 'audio/aac',
            caf: 'audio/x-caf',
            flac: 'audio/flac',
            oga: 'audio/ogg',
            wav: 'audio/wav',
            m3u8: 'application/x-mpegURL',
            mpd: 'application/dash+xml',
            jpg: 'image/jpeg',
            jpeg: 'image/jpeg',
            gif: 'image/gif',
            png: 'image/png',
            svg: 'image/svg+xml',
            webp: 'image/webp'
        };

        const extension = filepath.split('.').pop();
        const mimetype = mimeTypeCollection[extension.toLowerCase()];
        return mimetype || '';
    }
}