0.4.2 • Published 3 months ago

@teamsparta/sparta-player v0.4.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

A Simple React Component for using video.js

This package helps you use video.js like a simple React Component without worrying about the UI.

Usage Notice

April 24, 2025 — Now with TypeScript support!

The latest version of this package is based on TypeScript.

If you are using a pure JavaScript project,
please install version 0.3.19 as shown below:

npm install @teamsparta/sparta-player@0.3.19

Install

# using npm
npm install @teamsparta/sparta-player
# using yarn
yarn add @teamsparta/sparta-player

Sample UI

Usage

example 1 (with TypeScript)

import React from "react";
import { SpartaPlayer } from "@teamsparta/sparta-player";
import { useNavigate } from "react-router-dom";

const TestPage: React.FC = () => {
  const contentId = 0; // 예시, 실제 코드에서는 URL 파라미터 등에서 가져옴
  const navigate = useNavigate();
  const videoSrc =
    "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8";

  return (
    <SpartaPlayer
      source={videoSrc} // string, required
      videoType="application/x-mpegURL" // string, required
      autoPlay={true}
      controls={true}
      vttSource={vttSource}
      // thumbnail={'https://picsum.photos/1024/500'}
      isNoVttSourceAlert={true}
      noVttSourceAlertMessage="자막을 지원하지 않는 수업이에요."
      title={"제목 긴거 테스트스트스"}
      isNavigationOn={true}
      isAutoPlayButtonOn={true}
      isLoaded={isLoaded}
      defaultQuality={localStorage.getItem("quality") || "auto"}
      defaultPlaybackRate={localStorage.getItem("rate") || "1"}
      defaultSubtitle={localStorage.getItem("subtitle") || false}
      defaultFullscreen={localStorage.getItem("fullscreen") || false}
      defaultVolume={localStorage.getItem("volume") || 1}
      defaultMuted={localStorage.getItem("muted") || false}
      onReady={(player) => {}}
      // onPlay={() => console.log('onPlay')}
      // onPause={() => console.log('onPause')}
      // onEnded={() => console.log('onEnded')}
      // onTimeUpdate={(time) => console.log('onTimeUpdate', time)}
      onVolumeChange={(volume) =>
        localStorage.setItem("volume", JSON.stringify(volume))
      }
      onSeeking={(time) =>
        localStorage.setItem("seeking", JSON.stringify(time))
      }
      onMute={(isMuted) =>
        localStorage.setItem("muted", JSON.stringify(isMuted))
      }
      onPlaybackRateChange={(rate) =>
        localStorage.setItem("rate", JSON.stringify(rate))
      }
      onQualityChange={(quality) =>
        localStorage.setItem("quality", JSON.stringify(quality))
      }
      onSubtitleChange={(isSubtitle) =>
        localStorage.setItem("subtitle", JSON.stringify(isSubtitle))
      }
      onFullscreenChange={(isFullscreen) =>
        localStorage.setItem("fullscreen", JSON.stringify(isFullscreen))
      }
      onChangeAutoPlay={(isAutoPlay) =>
        localStorage.setItem("autoplay", JSON.stringify(isAutoPlay))
      }
      onClickPrev={() => {
        if (contentId > 0) {
          handleNavigate(contentId - 1);
        }
      }}
      // 다음 버튼
      onClickNext={() => {
        if (contentId < videoSources.length - 1) {
          handleNavigate(contentId + 1);
        }
      }}
    />
  );
};

example2 (with JavaScript)

import React from "react";
import { SpartaPlayer } from "@teamsparta/sparta-player";

export const TestPage = () => {
  return (
    <>
      <S.MobileWrapper>
        <LectureMobileNavBar />
        <SpartaPlayer
          title={"some video"}
          source={"https://www.w3schools.com/html/mov_bbb.mp4"}
          videoType="video/mp4"
          isNavigationOn={true}
        />
        <LectureTapMenu />
        <LectureMobileFloating isInitialized={isInitialized} />
      </S.MobileWrapper>
    </>
  );
};

props

Option nameDatatypeDefault valueDescription
sourcestring""required / Enter a video source.
videoTypestring""required / Enter a video type (e.g. 'video/mp4', 'application/x-mpegURL').
autoPlaybooleanfalseOn loaded whether the content will be started automatically or not
controlsbooleantrueWhether the player control bar will be shown or not
vttSourcestring""Enter a vtt source.
thumbnailstring""Enter a thumbnail image URL.
isNoVttSourceAlertbooleanfalseShow alert when no vtt source is available.
noVttSourceAlertMessagestring""Message for no vtt source alert.
titlestring""In the navigation, enter a title that you want to appear in the navigation.
isNavigationOnbooleanfalseYou can hide the navigation bar in the middle of the control bar.
isAutoPlayButtonOnbooleantrueShow auto play button in settings menu.
isLoadedbooleantrueWhether the player is loaded.
defaultQualitynumber | "auto""auto"Default video quality (360, 540, 720, 1080 or "auto").
defaultPlaybackRatenumber1Default playback rate.
defaultMutedbooleanfalseDefault muted state.
defaultVolumenumber1Default volume (0-1).
defaultSubtitlestring"false"Default subtitle state ("true" or "false").
onReady(player: any) => void() => {}Enter a function that will be triggered when the player is ready.
onPlay(time: number) => void() => {}Enter a function that will be triggered when the player starts.
onPause(time: number) => void() => {}Enter a function that will be triggered when the player pauses.
onEnded(time?: number) => void() => {}Enter a function to trigger when the player ends.
onTimeUpdate(time: number) => void() => {}Enter a function to trigger whenever the player time is updated.
onVolumeChange(volume: number) => void() => {}Enter a function to trigger when volume changes.
onSeeking(time: number) => void() => {}Enter a function to trigger during seeking.
onMute(muted: boolean) => void() => {}Enter a function to trigger when mute state changes.
onPlaybackRateChange(rate: number) => void() => {}Enter a function to trigger when playback rate changes.
onQualityChange(quality: number \| string) => void() => {}Enter a function to trigger when quality changes.
onSubtitleChange(enabled: boolean) => void() => {}Enter a function to trigger when subtitle state changes.
onFullscreenChange(fullscreen: boolean) => void() => {}Enter a function to trigger when fullscreen state changes.
onChangeAutoPlay(autoPlay: boolean) => void() => {}Enter a function to trigger when auto play state changes.
onClickPrev() => void() => {}In the navigation, enter a function that will be triggered when the Previous button is clicked.
onClickNext() => void() => {}In the navigation, enter a function that will be triggered when the Next button is clicked.

TypeScript Support

From version 0.4.0, SpartaPlayer supports TypeScript. The component comes with full type definitions for props, allowing better IDE support and catching potential errors at compile time.

import { SpartaPlayer, SpartaPlayerProps } from "@teamsparta/sparta-player";

// SpartaPlayerProps gives you access to all available prop types
const customProps: Partial<SpartaPlayerProps> = {
  source: "video.mp4",
  videoType: "video/mp4",
  onPlay: (time) => console.log(`Video started playing at ${time}s`),
};

// IDE will now provide type hinting and validation
const MyPlayer = () => <SpartaPlayer {...customProps} autoPlay />;

Notification

This package is developed and maintained by TeamSparta. Unfortunately, we are using a private workspace, which makes it difficult to publish to GitHub. If you have any issues or suggestions, please contact us at jungeun.lee@teamsparta.co

0.4.1

3 months ago

0.4.0

3 months ago

0.4.2

3 months ago

0.3.19

7 months ago

0.3.18

8 months ago

0.3.6

8 months ago

0.3.8

8 months ago

0.3.7

8 months ago

0.3.9

8 months ago

0.3.17

8 months ago

0.3.16

8 months ago

0.3.15

8 months ago

0.3.14

8 months ago

0.3.13

8 months ago

0.3.12

8 months ago

0.3.11

8 months ago

0.3.10

8 months ago

0.3.5

9 months ago

0.3.4

9 months ago

0.3.3

9 months ago

0.3.2

10 months ago

0.2.25

10 months ago

0.2.24

10 months ago

0.2.23

10 months ago

0.2.22

10 months ago

0.2.21

10 months ago

0.2.20

10 months ago

0.2.19

10 months ago

0.2.18

10 months ago

0.2.17

11 months ago

0.2.16

11 months ago

0.2.15

11 months ago

0.2.14

11 months ago

0.2.13

11 months ago

0.2.12

11 months ago

0.2.11

11 months ago

0.2.10

12 months ago

0.3.0

10 months ago

0.3.1

10 months ago

0.2.30

10 months ago

0.2.36

10 months ago

0.2.35

10 months ago

0.2.34

10 months ago

0.2.33

10 months ago

0.2.32

10 months ago

0.2.31

10 months ago

0.2.1

1 year ago

0.2.29

10 months ago

0.2.28

10 months ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.9

12 months ago

0.2.8

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.1.13

1 year ago

0.2.0

1 year ago

0.1.12

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.2

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.3

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.1

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago