0.4.4 • Published 5 months ago

@torutamahashi/video-player v0.4.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@torutamahashi/video-player

A highly customizable React video player component with chapter markers, subtitles, and thumbnail preview functionality.

Demo

movie

Features

  • 📝 Chapter and subtitle support with WebVTT format
  • 🖼 Thumbnail preview on seek bar hover
  • 🎨 Fully customizable styling with TailwindCSS
  • 🎯 Chapter markers on progress bar
  • 🔊 Advanced volume control
  • 🎨 Customizable icons
  • 📱 Responsive design
  • 🔧 TypeScript support

Installation

npm install @torutamahashi/video-player
# or
yarn add @torutamahashi/video-player
# or
pnpm add @torutamahashi/video-player

Add styling to your application

  1. React without tailwindcss

Add the following code at the beginning of the global style file.

// index.css 
@import '@torutamahashi/video-player/index.css';
  1. React + tailwindcss

You need to install tailwindcss in advance

// index.css
@import '@torutamahashi/video-player/index.css';
@tailwind base;
@tailwind components;
@tailwind utilities;
  1. Remix with tailwind css
// root.tsx
import videoPlayerStyles from '@torutamahashi/video-player/index.css?url';
import styles from './tailwind.css?url';
import type { LinksFunction } from '@remix-run/node';

export const links: LinksFunction = () => [
	{ rel: 'stylesheet', href: videoPlayerStyles },
	{ rel: 'stylesheet', href: styles },
];

Note: TailwindCSS is an optional peer dependency. You can use the default styles without it.

Basic Usage

import { VideoPlayer, Controls, useVideoPlayer } from '@torutamahashi/video-player';

function App() {
	const { videoRef, state, controls, videoPlayerProps } = useVideoPlayer()
	return (
		<VideoPlayer {...videoPlayerProps} src="path/to/video.mp4">
			<ControlsWrapper>
				<ProgressBar
					currentTime={state.currentTime}
					duration={state.duration}
					onSeek={controls.seek}
					height="sm"
					progressColor="#DC2626"
					videoRef={videoRef}
				/>
				<Controls
					videoRef={videoRef}
					isPlaying={state.isPlaying}
					currentTime={state.currentTime}
					duration={state.duration}
					volume={state.volume}
					onPlay={controls.play}
					onPause={controls.pause}
					onSeek={controls.seek}
					onVolumeChange={controls.setVolume}
				/>
			</ControlsWrapper>
		</VideoPlayer>
	);
}

Using Chapters and Subtitles

The player supports WebVTT format for both chapters and subtitles.

WebVTT Format Example

WEBVTT

00:00:00.000 --> 00:02:30.000
1.0 Introduction

00:02:30.000 --> 00:05:00.000
2.0 Main Content

Parsing WebVTT Files

Built-in parsers are available for both chapters and subtitles:

import { parseVTT } from '@torutamahashi/video-player';

// Parse subtitles
const subtitles = parseVTT(vttContent);

// Parse chapters
const chapters = parseVTT(vttContent);

Using Chapters in Component

see Demo

Icons

You can provide your own icons (default icons are included):

const customIcons = {
	Play: ({ className }) => <YourPlayIcon className={className} />,
	Pause: ({ className }) => <YourPauseIcon className={className} />,
	VolumeHigh: ({ className }) => <YourVolumeHighIcon className={className} />,
	VolumeMedium: ({ className }) => <YourVolumeMediumIcon className={className} />,
	VolumeLow: ({ className }) => <YourVolumeLowIcon className={className} />,
	VolumeX: ({ className }) => <YourVolumeXIcon className={className} />,
};

<Controls {...props} customIcons={customIcons} />;

TypeScript Support

The library includes comprehensive type definitions:

import type {
	VideoPlayerRefType,
	VideoPlayerPropsType,
	ChapterType,
	SubtitleType,
	WebVTTType,
} from '@torutamahashi/video-player';

const chapters: Chapter[] = [
	{
		startTime: 0,
		endTime: 150,
		title: 'Introduction',
	},
];

for now WebVTTType = SubtitleType = ChapterType

Contributing

Issues and Pull Requests are welcome! Please feel free to contribute to this project.

Feedback

We'd love to hear your thoughts, suggestions, or any issues you encounter while using @torutamahashi/video-player. Your feedback helps us improve and make the library even better!

How to Share Feedback

  • Bug Reports and Feature Requests
    Please open an issue.
    Use the provided templates for bug reports or feature requests to help us understand your feedback clearly.

  • Quick Feedback
    If you prefer, fill out this short feedback form.

License

MIT © Toru Tamahashi

0.3.0

6 months ago

0.3.6

6 months ago

0.3.5

6 months ago

0.3.8

6 months ago

0.3.7

6 months ago

0.3.2

6 months ago

0.3.1

6 months ago

0.3.4

6 months ago

0.3.3

6 months ago

0.3.9

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.4.4

5 months ago

0.4.1

6 months ago

0.4.0

6 months ago

0.4.3

5 months ago

0.4.2

5 months ago

0.1.31

6 months ago

0.1.30

6 months ago

0.1.29

6 months ago

0.1.28

6 months ago

0.1.27

6 months ago

0.1.26

6 months ago

0.1.25

6 months ago

0.1.24

6 months ago

0.1.23

6 months ago

0.1.22

6 months ago

0.1.21

6 months ago

0.1.20

6 months ago

0.1.19

6 months ago

0.1.18

6 months ago

0.1.17

6 months ago

0.1.16

6 months ago

0.1.15

6 months ago

0.1.14

6 months ago

0.1.13

6 months ago

0.1.12

6 months ago

0.1.11

6 months ago

0.1.10

6 months ago

0.1.8

6 months ago

0.1.7

6 months ago

0.1.6

6 months ago

0.1.5

6 months ago

0.1.4

6 months ago

0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.0

6 months ago