Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How to custom LoadingSpinner, it support to config? #8347

Closed
JonasWater opened this issue Jul 7, 2023 · 5 comments
Closed

How to custom LoadingSpinner, it support to config? #8347

JonasWater opened this issue Jul 7, 2023 · 5 comments
Labels
needs: triage This issue needs to be reviewed

Comments

@JonasWater
Copy link

Description

  1. How to show the vjs-control-text, i found it is hidden

  2. How to custom LoadingSpinner's vjs-control-text, just like below this, it supported?

loadingSpinner: {
  content: 'Is loading...'
}
image

Thx for your help~

Reduced test case

https://videojs.com/city

Steps to reproduce

Block the hls request within network devtools, and mock the loading.
https://videojs.com/city

image

Errors

No response

What version of Video.js are you using?

7.21.4

Video.js plugins used.

No response

What browser(s) including version(s) does this occur with?

Version 114

What OS(es) and version(s) does this occur with?

MacOS 12.4

@JonasWater JonasWater added the needs: triage This issue needs to be reviewed label Jul 7, 2023
@welcome
Copy link

welcome bot commented Jul 7, 2023

👋 Thanks for opening your first issue here! 👋

If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@amtins
Copy link
Contributor

amtins commented Jul 8, 2023

@JonasWater the naive approach, which handles internationalization, would be to do something like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Video.js - LoadingSpinner</title>

    <link
      rel="stylesheet"
      href="https://unpkg.com/video.js@next/dist/video-js.css"
    />

    <style>
      .vjs-loading-spinner {
        border: none;
        width: unset;
        height: unset;
        animation: none;
      }

      .vjs-seeking .vjs-loading-spinner::before,
      .vjs-seeking .vjs-loading-spinner::after,
      .vjs-waiting .vjs-loading-spinner::before,
      .vjs-waiting .vjs-loading-spinner::after {
        display: none;
        animation: none;
        border: unset;
        animation-delay: unset;
      }

      .video-js .vjs-loading-spinner .vjs-control-text {
        width: unset;
        position: unset;
        height: unset;
        font-size: 2em;
        font-weight: bold;
        background-color: red;
      }
    </style>
  </head>
  <body>
    <video-js
      id="player"
      class="video-js vjs-has-started"
      controls
      muted
    ></video-js>

    <script type="module">
     import 'https://unpkg.com/video.js@next/dist/video.js';

      const player = videojs(
        'player',
        {
          languages: {
            fr: {
              'Loading...': 'Chargement...',
            },
          },
        },
        () => {
          const loadSpinnerControlText =
            '.vjs-loading-spinner .vjs-control-text';

          player.$(loadSpinnerControlText).textContent =
            player.loadingSpinner.localize('Loading...');

          player.on('languagechange', () => {
            player.$(loadSpinnerControlText).textContent =
              player.loadingSpinner.localize('Loading...');
          });
        }
      );

      player.src({
        src: 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
        type: 'application/x-mpegURL',
      });
    </script>
  </body>
</html>

@video-archivist-bot
Copy link

Hey! We've detected some video files in a comment on this issue. If you'd like to permanently archive these videos and tie them to this project, a maintainer of the project can reply to this issue with the following commands:

@amtins
Copy link
Contributor

amtins commented Jul 8, 2023

Or if you want a custom component:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Video.js - LoadingSpinner</title>

    <link
      rel="stylesheet"
      href="https://unpkg.com/video.js@next/dist/video-js.css"
    />

    <style>
      .vjs-loading-spinner {
        border: none;
        width: unset;
        height: unset;
        animation: none;
      }

      .vjs-seeking .vjs-loading-spinner::before,
      .vjs-seeking .vjs-loading-spinner::after,
      .vjs-waiting .vjs-loading-spinner::before,
      .vjs-waiting .vjs-loading-spinner::after {
        display: none;
        animation: none;
        border: unset;
        animation-delay: unset;
      }

      .video-js .vjs-loading-spinner .vjs-control-text {
        width: unset;
        position: unset;
        height: unset;
        font-size: 2em;
        font-weight: bold;
        background-color: red;
      }
    </style>
  </head>
  <body>
    <video-js
      id="player"
      class="video-js vjs-has-started"
      controls
      muted
    ></video-js>

    <script src="https://unpkg.com/video.js@next/dist/video.js"></script>
    <script type="module">
      import 'https://unpkg.com/video.js@next/dist/video.js';

      class CustomLoadingSpinner extends videojs.getComponent( 'LoadingSpinner' ) {
        createEl() {
          const { controlText } = this.options();

          const text = videojs.dom.createEl('span', {
            className: 'vjs-control-text',
            textContent: this.localize(controlText || 'Loading...'),
          });

          const el = videojs.dom.createEl(
            'div',
            {
              className: 'vjs-loading-spinner',
              dir: 'ltr',
            },
            {},
            text
          );

          return el;
        }

        handleLanguagechange() {
          const { controlText } = this.options();
          this.$('.vjs-control-text').textContent = this.localize(
            controlText || 'Loading...'
          );
        }
      }

      videojs.registerComponent('LoadingSpinner', CustomLoadingSpinner);

      const controlText = 'My custom text...';

      const player = videojs(
        'player',
        {
          loadingSpinner: {
            controlText
          },
          languages: {
            fr: {
              'Loading...': 'Chargement...',
              [controlText]: 'Mon composant custom...'
            },
          },
        }
      );

      player.src({
        src: 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
        type: 'application/x-mpegURL',
      });
    </script>
  </body>
</html>

@video-archivist-bot
Copy link

Hey! We've detected some video files in a comment on this issue. If you'd like to permanently archive these videos and tie them to this project, a maintainer of the project can reply to this issue with the following commands:

@videojs videojs locked and limited conversation to collaborators Jul 8, 2023
@amtins amtins converted this issue into discussion #8350 Jul 8, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
needs: triage This issue needs to be reviewed
Projects
None yet
Development

No branches or pull requests

3 participants