Skip to content
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

fix(useMediaControls): Doesn't rewrite default media properties #500

Merged
merged 2 commits into from
May 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 25 additions & 15 deletions packages/core/useMediaControls/index.ts
Expand Up @@ -205,14 +205,6 @@ function tracksToArray(tracks: TextTrackList): UseMediaTextTrack[] {

const defaultOptions: UseMediaControlsOptions = {
src: '',
poster: '',
autoplay: false,
preload: 'auto',
loop: false,
controls: false,
muted: false,
playsinline: false,
autoPictureInPicture: false,
tracks: [],
}

Expand Down Expand Up @@ -310,14 +302,32 @@ export function useMediaControls(target: MaybeRef<HTMLMediaElement | null | unde
if (!el)
return

el.loop = unref(options.loop)!
el.controls = unref(options.controls)!
el.muted = unref(options.muted)!
el.preload = unref(options.preload)!
el.autoplay = unref(options.autoplay)!
const loop = unref(options.loop)
if (loop !== undefined) el.loop = loop

const controls = unref(options.controls)
if (controls !== undefined) el.controls = controls

const muted = unref(options.muted)
if (muted !== undefined) el.muted = muted

const preload = unref(options.preload)
if (preload !== undefined) el.preload = preload

const autoplay = unref(options.autoplay)
if (autoplay !== undefined) el.autoplay = autoplay

const poster = unref(options.poster)
if (poster !== undefined) (el as HTMLVideoElement).poster = poster

const playsInline = unref(options.playsinline)
if (playsInline !== undefined) (el as HTMLVideoElement).playsInline = playsInline

const autoPictureInPicture = unref(options.autoPictureInPicture)
// @ts-expect-error HTMLVideoElement.autoPictureInPicture not implemented in TS
if (autoPictureInPicture !== undefined) (el as HTMLVideoElement).autoPictureInPicture = autoPictureInPicture

el.volume = unref(volume)!
;(el as HTMLVideoElement).playsInline = unref(options.playsinline)!
;(el as HTMLVideoElement).poster = unref(options.poster) || ''
})

/**
Expand Down