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

Video Block #33

Closed
jbmoelker opened this issue Oct 26, 2023 · 1 comment · Fixed by #119
Closed

Video Block #33

jbmoelker opened this issue Oct 26, 2023 · 1 comment · Fixed by #119
Assignees
Labels
good first issue Good for newcomers

Comments

@jbmoelker
Copy link
Member

jbmoelker commented Oct 26, 2023

User story

As an editor,
I want a video block in the CMS that supports uploading my own video,
so that I can add videos to any page without using a 3rd party service like YouTube or Vimeo.

See #32 for 3rd party Video Embed Block.

Checklist

  • Supports uploading own video
  • Supports being used in both modular content and structured text
  • Only autoplays if autoplay and !window.matchMedia('(prefers-reduced-motion: reduce)').matches for a11y

Content model

Video Block

  • title: string (single-line), optional
  • video: asset, file extension: video, required
  • autoplay: boolean
  • mute: boolean
  • loop: boolean
  • tracks?: { kind, label, (.vtt)file } (for a11y. maps to <track>s)
@jbmoelker
Copy link
Member Author

jbmoelker commented Nov 28, 2023

Use official Mux components?

Relatively heavy. Lazy load on intent? Use custom Astro directive client:click?

Or create our own custom element, using hls.js, just like the Mux components do?

This is from one of our Vue projects:

<video 
  id="video-player"
  :poster="`${poster}?w=640&auto=format`"
  controls
/>
<script>
  const getHlsPlayer = () => import('hls.js')

  export default {
    mounted() {
      getHlsPlayer().then(({ default: Hls }) => {
        const video = document.getElementById('video-player')

        if (Hls.isSupported()) {
          const hls = new Hls()
          hls.loadSource(this.video.video.streamingUrl)
          hls.attachMedia(video)
          hls.on(Hls.Events.MANIFEST_PARSED, () => {
            video.play()
          })
        } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
          video.src = this.video.video.streamingUrl
          video.addEventListener('loadedmetadata',() => {
            video.play()
          })
        }
      })
    },
  }
</script>

@jbmoelker jbmoelker added the good first issue Good for newcomers label Dec 25, 2023
This was referenced Jan 23, 2024
jbmoelker added a commit that referenced this issue Jan 29, 2024
# Changes

Adds Video Block that renders a video uploaded in DatoCMS with a cover
image, caption, support for subtitles and options to autoplay, mute and
loop. Features (also in block readme):

- Privacy first alternative to [Video Embed Block](../VideoEmbedBlock/),
as video uploaded in DatoCMS is served without tracking (no consent
required).
- Supports video streaming with adaptive bitrate (using HLS) for best UX
and performance.
- Fallback to mp4 video when streaming is not available.
- Fallback to video download link when HTML video element is not
supported.
- Supports subtitle tracks for enhanced accessibility, automatically
selecting default locale when available.
- Supports figcaption defaulting to external video's title and optional
custom title override.
- Supports autoplay, mute and loop.
- Autoplay is only triggered if no reduced motion is preferred (for
a11y) and save data mode is off.
- Conditionally loads video and streaming package (`hls.js`) on click or
when in view in case autoplay is enabled.

Moved [custom image and custom play button overlay to separate
ticket](#121).

# Associated issue

Resolves #33 

# How to test

1. Open
[`/en/overview-page/demos/video-block/`](https://feat-video-block.head-start.pages.dev/en/overview-page/demos/video-block/)
2. Test with different uploaded videos in CMS, with and without
subtitles
3. Verify streaming, mp4 and fallback work (by disabling one at a time
locally)
4. Verify autoplay and other block options work as expected

# Checklist

- [x] I have performed a self-review of my own code
- [x] I have made sure that my PR is easy to review (not too big,
includes comments)
- [x] I have made updated relevant documentation files (in project
README, docs/, etc)
- ~~I have added a decision log entry if the change affects the
architecture or changes a significant technology~~
- [x] I have notified a reviewer

<!-- Please strike through and check off all items that do not apply
(rather than removing them) -->
@jbmoelker jbmoelker self-assigned this Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant