JSPM

  • Created
  • Published
  • Downloads 830
  • Score
    100M100P100Q114539F
  • License MIT

A Simple React Component for video.js with TypeScript support

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@teamsparta/sparta-player) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    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

    image

    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 name Datatype Default value Description
    source string "" required / Enter a video source.
    videoType string "" required / Enter a video type (e.g. 'video/mp4', 'application/x-mpegURL').
    autoPlay boolean false On loaded whether the content will be started automatically or not
    controls boolean true Whether the player control bar will be shown or not
    vttSource string "" Enter a vtt source.
    thumbnail string "" Enter a thumbnail image URL.
    isNoVttSourceAlert boolean false Show alert when no vtt source is available.
    noVttSourceAlertMessage string "" Message for no vtt source alert.
    title string "" In the navigation, enter a title that you want to appear in the navigation.
    isNavigationOn boolean false You can hide the navigation bar in the middle of the control bar.
    isAutoPlayButtonOn boolean true Show auto play button in settings menu.
    isLoaded boolean true Whether the player is loaded.
    defaultQuality number | "auto" "auto" Default video quality (360, 540, 720, 1080 or "auto").
    defaultPlaybackRate number 1 Default playback rate.
    defaultMuted boolean false Default muted state.
    defaultVolume number 1 Default volume (0-1).
    defaultSubtitle string "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