-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated video dimensions to fit view horizontal/vertical #10101
Changes from 2 commits
d35a927
9423ab9
7c5c9a5
f3ca42d
5d7dc55
ddec04a
4af20d1
5f4ef3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
<template> | ||
<video :key="`media-video-${file.id}`" controls preload="preload" :autoplay="isAutoPlayEnabled"> | ||
<video | ||
ref="video" | ||
:key="`media-video-${file.id}`" | ||
controls | ||
preload="preload" | ||
:autoplay="isAutoPlayEnabled" | ||
@loadedmetadata="updateDimensions" | ||
> | ||
<source :src="file.url" :type="file.mimeType" /> | ||
</video> | ||
</template> | ||
|
@@ -18,6 +25,23 @@ export default defineComponent({ | |
type: Boolean, | ||
default: true | ||
} | ||
}, | ||
beforeUnmount() { | ||
window.removeEventListener('resize', this.resizeVideoDimensions) | ||
}, | ||
methods: { | ||
updateDimensions() { | ||
this.resizeVideoDimensions() | ||
window.addEventListener('resize', this.resizeVideoDimensions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each time this method gets called you register an event listener, is this done intentionally? Wouldn't it make more sense to register the event listener once on mount? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh.. my bad, you are right. At first I was working with the videoWidth and videoHeight, then change it to setting max dimensions and didn't update this. Yeah, thats completely reasonable to set in onMounted |
||
}, | ||
resizeVideoDimensions() { | ||
const maxHeight = document.querySelector('.stage_media')?.offsetHeight - 10 ?? null | ||
const maxWidth = document.querySelector('.stage_media')?.offsetWidth - 10 ?? null | ||
if (maxHeight && maxWidth && this.$refs.video) { | ||
this.$refs.video.style.maxHeight = `${maxHeight}px` | ||
this.$refs.video.style.maxWidth = `${maxWidth}px` | ||
} | ||
} | ||
} | ||
}) | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the composition API by adding the methods and
onBeforeUnmount
insetup
.