Skip to content

Commit

Permalink
chore: muted ref added
Browse files Browse the repository at this point in the history
  • Loading branch information
asadbek064 committed Aug 26, 2023
1 parent 52741eb commit 3dfc0b0
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
15 changes: 8 additions & 7 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@ const initialCode = `
<Player
sources={[
{
file: 'https://artplayer.org/assets/sample/video.mp4'
file: 'https://huggingface.co/datasets/light064/ReactAllPlayer/resolve/main/View_From_A_Blue_Moon_Trailer-1080p.mp4'
}
]}
subtitles={[
{
lang: 'jp',
language: 'Japanese',
file: 'https://artplayer.org/assets/sample/subtitle.jp.srt'
lang: 'en',
language: 'English',
file: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt'
},
{
lang: 'cn',
language: 'Chinese',
file: 'https://artplayer.org/assets/sample/subtitle.cn.srt'
lang: 'fr',
language: 'French ',
file: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt'
}
]}
className="object-contain w-full h-full"
thumbnail="https://preview.zorores.com/8b/8bc17ab9537166f2abb7e0bef2b57e23/thumbnails/sprite.vtt"
autoPlay
muted
/>
`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.4",
"version": "2.0.6",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
10 changes: 9 additions & 1 deletion src/components/Controls/VolumeButton/VolumeButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo, useRef } from 'react';
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import { useVideo } from '../../../contexts/VideoContext';
import { useVideoProps } from '../../../contexts/VideoPropsContext';
import useHotKey, { parseHotKey } from '../../../hooks/useHotKey';
Expand All @@ -24,6 +24,12 @@ const VolumeButton = () => {
const hotkey = useHotKey('volume');
const previousVolume = useRef(videoState.volume);

useEffect(() => {
if(videoEl?.muted) {
videoState.volume = 0;
}
})

const VolumeComponent = useMemo(() => {
const entries = Object.entries(VolumeComponents).sort(
(a, b) => Number(a[0]) - Number(b[0])
Expand All @@ -41,6 +47,8 @@ const VolumeButton = () => {
const handleClick = useCallback(() => {
if (!videoEl) return;

if (videoEl.muted) videoEl.muted = false;

if (videoEl.volume === 0) {
videoEl.volume = previousVolume.current;
} else {
Expand Down
15 changes: 5 additions & 10 deletions src/components/DefaultUI/DefaultUI.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import * as React from 'react';
import { useInteract } from '../../contexts/VideoInteractingContext';
import { Components, ReactVidPlayerProps } from '../../contexts/VideoPropsContext';
import {
Components,
ReactVidPlayerProps,
} from '../../contexts/VideoPropsContext';
import useDoubleTap from '../../hooks/useDoubleTap';
import useGlobalHotKeys from '../../hooks/useGlobalHotKeys';
import { clamp, classNames } from '../../utils';
import { isMobile } from '../../utils/device';
import { IndicatorRef } from '../Indicator/Indicator';
import styles from './DefaultUI.module.css';

import Controls, { MobileVolumeSlider } from '../Controls';
import Controls from '../Controls';
import MobileBackwardIndicator from '../Indicator/MobileBackwardIndicator';
import MobileForwardIndicator from '../Indicator/MobileForwardIndicator';
import MobileControls from '../MobileControls';
Expand All @@ -30,7 +33,6 @@ const defaultComponents: Components = {
Overlay,
Player,
Subtitle,
MobileVolumeSlider,
};

const DefaultUI = React.forwardRef<HTMLVideoElement, ReactVidPlayerProps>(
Expand Down Expand Up @@ -85,9 +87,6 @@ const DefaultUI = React.forwardRef<HTMLVideoElement, ReactVidPlayerProps>(
Overlay: components?.Overlay || defaultComponents.Overlay,
Player: components?.Player || defaultComponents.Player,
Subtitle: components?.Subtitle || defaultComponents.Subtitle,
MobileVolumeSlider:
components?.MobileVolumeSlider ||
defaultComponents.MobileVolumeSlider,
}),
[components]
);
Expand Down Expand Up @@ -239,10 +238,6 @@ const DefaultUI = React.forwardRef<HTMLVideoElement, ReactVidPlayerProps>(
<uiComponents.MobileBackwardIndicator ref={backIndicatorRef} />
<uiComponents.MobileForwardIndicator ref={forwardIndicatorRef} />

{!disableVolumeSlider && (
<uiComponents.MobileVolumeSlider ref={volumeSliderRef} />
)}

<uiComponents.Subtitle />

<div className={styles.playerContainer}>
Expand Down
3 changes: 3 additions & 0 deletions src/components/Player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface PlayerProps extends React.HTMLAttributes<HTMLVideoElement> {
onDashInit?: (dash: DashJS.MediaPlayerClass, currentSource: Source) => void;
onInit?: (videoEl: HTMLVideoElement) => void;
autoPlay?: boolean;
muted?: boolean;
preferQuality?: (qualities: string[]) => string;
hlsVersion?: string;
dashVersion?: string;
Expand All @@ -54,6 +55,7 @@ const Player = React.forwardRef<HTMLVideoElement, PlayerProps>(
onDashInit = noop,
onInit = noop,
autoPlay = false,
muted = false,
preferQuality,
hlsVersion,
dashVersion,
Expand Down Expand Up @@ -442,6 +444,7 @@ const Player = React.forwardRef<HTMLVideoElement, PlayerProps>(
<video
ref={playerRef}
autoPlay={autoPlay}
muted={muted}
preload="auto"
className={styles.video}
playsInline
Expand Down
8 changes: 7 additions & 1 deletion src/contexts/GlobalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ import { VideoStateContextProvider } from './VideoStateContext';
const GlobalContext: React.FC<ReactVidPlayerProps> = ({
sources,
subtitles = [],
placeholder,
children,
...props
}) => {
return (
<VideoPropsProvider sources={sources} subtitles={subtitles} {...props}>
<VideoPropsProvider
sources={sources}
subtitles={subtitles}
placeholder={placeholder}
{...props}
>
<VideoStateContextProvider>
<VideoInteractingContextProvider>
<SubtitleSettingsProvider>{children}</SubtitleSettingsProvider>
Expand Down
4 changes: 1 addition & 3 deletions src/contexts/VideoPropsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ export type Components = {
MobileForwardIndicator: React.ForwardRefExoticComponent<
React.RefAttributes<IndicatorRef>
>;
MobileVolumeSlider: React.ForwardRefExoticComponent<
React.RefAttributes<IndicatorRef>
>;
Player: React.ForwardRefExoticComponent<
PlayerProps & React.RefAttributes<HTMLVideoElement>
>;
Expand All @@ -68,6 +65,7 @@ export type Components = {

export interface ReactVidPlayerProps extends PlayerProps {
thumbnail?: string;
placeholder?: string;
i18n?: I18n;
shortcuts?: Shortcuts;
hotkeys?: HotKey[];
Expand Down

0 comments on commit 3dfc0b0

Please sign in to comment.