Path: blob/main/extensions/media-preview/media/audioPreview.js
3292 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4// @ts-check5"use strict";67(function () {8// @ts-ignore9const vscode = acquireVsCodeApi();1011function getSettings() {12const element = document.getElementById('settings');13if (element) {14const data = element.getAttribute('data-settings');15if (data) {16return JSON.parse(data);17}18}1920throw new Error(`Could not load settings`);21}2223const settings = getSettings();2425// State26let hasLoadedMedia = false;2728// Elements29const container = document.createElement('div');30container.className = 'audio-container';31document.body.appendChild(container);3233const audio = new Audio(settings.src === null ? undefined : settings.src);34audio.controls = true;3536function onLoaded() {37if (hasLoadedMedia) {38return;39}40hasLoadedMedia = true;4142document.body.classList.remove('loading');43document.body.classList.add('ready');44container.append(audio);45}4647audio.addEventListener('error', e => {48if (hasLoadedMedia) {49return;50}5152hasLoadedMedia = true;53document.body.classList.add('error');54document.body.classList.remove('loading');55});5657if (settings.src === null) {58onLoaded();59} else {60audio.addEventListener('canplaythrough', () => {61onLoaded();62});63}6465document.querySelector('.open-file-link')?.addEventListener('click', (e) => {66e.preventDefault();67vscode.postMessage({68type: 'reopen-as-text',69});70});71}());727374