diff --git a/src/appComponent.tsx b/src/appComponent.tsx index dfbf929..cab5007 100644 --- a/src/appComponent.tsx +++ b/src/appComponent.tsx @@ -94,10 +94,11 @@ const AppComponent = memo(function AppComponent(props) { option={{ videoSrc: 'https://gs-files.oss-accelerate.aliyuncs.com/okr/prod/file/2021/08/10/1628605591454mda-met51bhiqb2sgjzd.mp4', - width: 750, - height: 420, + width: 500, + height: 320, theme: 'red', poster: 'https://cdn.gudsen.com/2021/06/28/f81356b08b4842d7a3719499f557c8e4.JPG', + pausePlacement: 'center', }} /> diff --git a/src/assets/css/mixin.scss b/src/assets/css/mixin.scss index 81b4721..31297c1 100644 --- a/src/assets/css/mixin.scss +++ b/src/assets/css/mixin.scss @@ -37,3 +37,19 @@ opacity: 1; } } +@keyframes scaleAnimate { + 50% { + transform: scale(1.2); + } + 100% { + transform: scale(1); + } +} +@keyframes rotateAnimate { + 0% { + transform: rotate(270deg); + } + 100% { + transform: rotate(360deg); + } +} diff --git a/src/components/svgIcon/index.tsx b/src/components/svgIcon/index.tsx index 6b530e6..df9d098 100644 --- a/src/components/svgIcon/index.tsx +++ b/src/components/svgIcon/index.tsx @@ -4,6 +4,7 @@ export type svgProps = { fill?: string; fontSize?: string; className?: string; + style?: React.CSSProperties; onClick?: React.MouseEventHandler; }; @@ -13,12 +14,13 @@ const SvgIcon: React.FC = memo(function SvgIcon({ fontSize = '18px', className, onClick, + style, }) { const iconName = useMemo(() => '#icon-' + iconClass, [iconClass]); return (
)}
diff --git a/src/core/controls/index.scss b/src/core/controls/index.scss index cdf6f86..fe8d6cc 100644 --- a/src/core/controls/index.scss +++ b/src/core/controls/index.scss @@ -40,6 +40,7 @@ text-align: center; line-height: 42px; &-multiple { + cursor: pointer; padding: 0 10px; position: relative; &-container { @@ -78,6 +79,7 @@ &-volume { padding: 0 10px; position: relative; + cursor: pointer; &:hover { z-index: 1000000000; &-layer { @@ -147,6 +149,7 @@ &-set { padding: 0 10px; position: relative; + cursor: pointer; &-container { @include wh(100%, 70px); @include position(absolute, -12px, auto, 0, 50%); @@ -155,7 +158,10 @@ } &:hover { z-index: 1000000000; - .multifunction-set-layer { + .hover-icon-rotateAnimate { + animation: rotateAnimate 0.5s ease; + } + .JoL-multifunction-set-layer { animation: show 0.3s ease; } } @@ -176,4 +182,9 @@ } } } + .hover-icon-animate { + &:hover { + animation: scaleAnimate 0.5s ease; + } + } } diff --git a/src/core/controls/index.tsx b/src/core/controls/index.tsx index 464575c..e10b605 100644 --- a/src/core/controls/index.tsx +++ b/src/core/controls/index.tsx @@ -1,13 +1,13 @@ import React, { memo, useContext, useRef, useEffect, useMemo, useCallback } from 'react'; import Broadcast from '@/components/svgIcon'; import Tooltip from '@/components/tooltip'; -import { FlowContext, contextType } from '@/core/context'; +import { FlowContext } from '@/core/context'; import { useVideo } from '@/core/useVideo'; import { secondsToMinutesAndSecondes, createALabel } from '@/utils'; import { useControls } from './variable'; import useWindowClient from '@/utils/useWindowClient'; import screenfull, { Screenfull } from 'screenfull'; -import { multipleList } from '@/core/config'; +import { multipleList, defaultVolume } from '@/core/config'; import SetComponent from './set'; import MultipleComponent from './multiple'; import VolumeComponent from './volume'; @@ -87,6 +87,7 @@ const Index = memo(function Index(props) { * @description 音量滑动元素点击 */ const changeCurrentVolume: React.MouseEventHandler = (e) => { + e.stopPropagation(); const volumeSliderMirrorElement = ( volumeSliderMirror.current as HTMLDivElement & { element: HTMLDivElement } ).element; @@ -99,7 +100,8 @@ const Index = memo(function Index(props) { updateCurrentVolume(volumePercent); }; - const slideCurrentVolume = () => { + const slideCurrentVolume: React.MouseEventHandler = (e) => { + e.stopPropagation(); const volumeSliderMirrorElement = ( volumeSliderMirror.current as HTMLDivElement & { element: HTMLDivElement } ).element; @@ -123,7 +125,8 @@ const Index = memo(function Index(props) { volumeInterval.current && clearInterval(volumeInterval.current); dispatch({ type: 'isSlideVolume', data: false }); }; - const clearVolumeInterval = () => { + const clearVolumeInterval: React.MouseEventHandler = (e) => { + e.stopPropagation(); whenMouseUpDo(); }; /** @@ -201,6 +204,15 @@ const Index = memo(function Index(props) { dispatch({ type: 'isWebPageFullScreen', data: true }); } }; + /** + * @description 静音键和非静音键的切换 + */ + const toggleVolume = () => { + reviceProps.videoRef!.volume = controlsState.isMuted ? defaultVolume / 100 : 0; + dispatch({ type: 'isMuted', data: controlsState.isMuted ? false : true }); + reviceProps.videoRef!.muted = controlsState.isMuted ? false : true; + }; + return (
} + icon={ + + } /> @@ -250,6 +272,7 @@ const Index = memo(function Index(props) { @@ -264,6 +287,7 @@ const Index = memo(function Index(props) { fill="#fff" fontSize={'20px'} onClick={requestFullScreen} + className="hover-icon-animate" /> } /> diff --git a/src/core/controls/multiple.tsx b/src/core/controls/multiple.tsx index 5c5ed7a..775d42c 100644 --- a/src/core/controls/multiple.tsx +++ b/src/core/controls/multiple.tsx @@ -23,8 +23,8 @@ const Multiple: FC = memo(function Multiple({ return (
[setIsShow(true), e.stopPropagation()]} - onMouseLeave={(e) => [setIsShow(false), e.stopPropagation()]} + onClick={(e) => setIsShow((pre) => !pre)} + onMouseLeave={(e) => [setIsShow(false)]} >

{multipleText}

= memo(function Multiple({
    {multipleList.map((item, index) => (
  • [selectPlayRate(item.id), setIsShow(false)]} + onClick={(e) => [selectPlayRate(item.id), setIsShow(false), e.stopPropagation()]} key={index} style={{ color: multiple === item.id ? (theme ? theme : defaultTheme) : '#fff' }} > diff --git a/src/core/controls/set.tsx b/src/core/controls/set.tsx index 95338b6..fc3ae81 100644 --- a/src/core/controls/set.tsx +++ b/src/core/controls/set.tsx @@ -1,7 +1,6 @@ import React, { memo, FC, useState, useContext } from 'react'; import Broadcast from '@/components/svgIcon'; import Switch from '@/components/switch'; - import { FlowContext } from '@/core/context'; import './index.scss'; @@ -19,9 +18,9 @@ const Set: FC = memo(function Set({ switchChange }) {
    [setIsShow(true), e.stopPropagation()]} - onMouseLeave={(e) => [setIsShow(false), e.stopPropagation()]} + onMouseLeave={(e) => [setIsShow(false)]} > - +
    { * @description 是否网页全屏 */ isWebPageFullScreen: K; + /** + * @description 是否静音 + */ + isMute: K; } export interface volumeActionType { @@ -51,13 +55,18 @@ export interface isWebPageFullScreenActionType { type: 'isWebPageFullScreen'; data: controlsVariableType['isWebPageFullScreen']; } +export interface isMuteActionType { + type: 'isMute'; + data: controlsVariableType['isMute']; +} export type mergeAction = | volumeActionType | isMutedActionType | isSlideVolumeActionType | isScreentFullActionType | multipleActionType - | isWebPageFullScreenActionType; + | isWebPageFullScreenActionType + | isMuteActionType; export const useControls = () => { const initialState = { @@ -67,6 +76,7 @@ export const useControls = () => { isScreentFull: false, multiple: 1.0, isWebPageFullScreen: false, + isMute: false, }; const reducer = (state: controlsVariableType, action: mergeAction) => { @@ -83,6 +93,8 @@ export const useControls = () => { return { ...state, multiple: action.data }; case 'isWebPageFullScreen': return { ...state, isWebPageFullScreen: action.data }; + case 'isMute': + return { ...state, isMute: action.data }; default: return state; } diff --git a/src/core/controls/volume.tsx b/src/core/controls/volume.tsx index 5182561..1d72d3d 100644 --- a/src/core/controls/volume.tsx +++ b/src/core/controls/volume.tsx @@ -6,13 +6,22 @@ import './index.scss'; export interface VolumeType { volume: number; + isMuted: boolean; changeCurrentVolume: React.MouseEventHandler; slideCurrentVolume: React.MouseEventHandler; clearVolumeInterval: React.MouseEventHandler; + toggleVolume: Function; } const Volume = function Volume( - { volume, changeCurrentVolume, slideCurrentVolume, clearVolumeInterval }: VolumeType, + { + volume, + changeCurrentVolume, + slideCurrentVolume, + clearVolumeInterval, + isMuted, + toggleVolume, + }: VolumeType, ref: React.Ref | undefined, ) { const volumeSliderMirror = useRef(null); @@ -30,10 +39,11 @@ const Volume = function Volume( return (
    [setIsShow(true), e.stopPropagation()]} - onMouseLeave={(e) => [setIsShow(false), e.stopPropagation()]} + onMouseEnter={(e) => [setIsShow(true)]} + onMouseLeave={(e) => [setIsShow(false)]} + onClick={(e) => [toggleVolume()]} > - +