From 46e83a26131689869cee8d02ceb594ec46bcaa58 Mon Sep 17 00:00:00 2001 From: Fawzi Abdulfattah Date: Wed, 21 Jun 2023 20:51:00 +0300 Subject: [PATCH] feat: adding optional support for auto playing and looping videos (#184758) * feat: adding options to support videos looping and auto playing Signed-off-by: Fawzi Abdulfattah * chore: adding on mute to the videos auto play setting's description Signed-off-by: Fawzi Abdulfattah --------- Signed-off-by: Fawzi Abdulfattah --- extensions/media-preview/media/videoPreview.js | 3 +++ extensions/media-preview/package.json | 16 ++++++++++++++++ extensions/media-preview/package.nls.json | 2 ++ extensions/media-preview/src/videoPreview.ts | 3 +++ 4 files changed, 24 insertions(+) diff --git a/extensions/media-preview/media/videoPreview.js b/extensions/media-preview/media/videoPreview.js index 4cf22d3b446..eeed26972a3 100644 --- a/extensions/media-preview/media/videoPreview.js +++ b/extensions/media-preview/media/videoPreview.js @@ -33,6 +33,9 @@ } video.playsInline = true; video.controls = true; + video.autoplay = settings.autoplay; + video.muted = settings.autoplay; + video.loop = settings.loop; function onLoaded() { if (hasLoadedMedia) { diff --git a/extensions/media-preview/package.json b/extensions/media-preview/package.json index 795316f8b89..02d4fa12fe0 100644 --- a/extensions/media-preview/package.json +++ b/extensions/media-preview/package.json @@ -27,6 +27,22 @@ } }, "contributes": { + "configuration": { + "type": "object", + "title": "Media Previewer", + "properties": { + "previewer.videos.autoPlay": { + "type": "boolean", + "default": false, + "markdownDescription": "%videoPreviewerAutoPlay%" + }, + "previewer.videos.loop": { + "type": "boolean", + "default": false, + "markdownDescription": "%videoPreviewerLoop%" + } + } + }, "customEditors": [ { "viewType": "imagePreview.previewEditor", diff --git a/extensions/media-preview/package.nls.json b/extensions/media-preview/package.nls.json index 27fe241cf6b..c45e1e2613b 100644 --- a/extensions/media-preview/package.nls.json +++ b/extensions/media-preview/package.nls.json @@ -4,6 +4,8 @@ "customEditor.audioPreview.displayName": "Audio Preview", "customEditor.imagePreview.displayName": "Image Preview", "customEditor.videoPreview.displayName": "Video Preview", + "videoPreviewerAutoPlay": "Start playing videos on mute automatically.", + "videoPreviewerLoop": "Loop videos over again automatically.", "command.zoomIn": "Zoom in", "command.zoomOut": "Zoom out", "command.copyImage": "Copy" diff --git a/extensions/media-preview/src/videoPreview.ts b/extensions/media-preview/src/videoPreview.ts index 5897792f667..a414935a46f 100644 --- a/extensions/media-preview/src/videoPreview.ts +++ b/extensions/media-preview/src/videoPreview.ts @@ -54,8 +54,11 @@ class VideoPreview extends MediaPreview { protected async getWebviewContents(): Promise { const version = Date.now().toString(); + const configurations = vscode.workspace.getConfiguration('previewer.videos'); const settings = { src: await this.getResourcePath(this.webviewEditor, this.resource, version), + autoplay: configurations.get('autoPlay'), + loop: configurations.get('loop'), }; const nonce = getNonce();