Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add startLevel prop to mux-video-react #772

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/mux-video-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const playerSoftwareVersion = getPlayerVersion();
const playerSoftwareName = 'mux-video-react';

const MuxVideo = React.forwardRef<HTMLVideoElement | undefined, Partial<Props>>((props, ref) => {
const { playbackId, src: outerSrc, children, autoPlay, preload, streamType, ...restProps } = props;
const { playbackId, src: outerSrc, children, autoPlay, preload, streamType, startLevel, ...restProps } = props;

const [playerInitTime] = useState(generatePlayerInitTime());
const [src, setSrc] = useState<MuxMediaProps['src']>(toMuxVideoURL(playbackId) ?? outerSrc);
Expand Down Expand Up @@ -89,6 +89,7 @@ MuxVideo.propTypes = {
type: PropTypes.oneOf(allMediaTypes),
streamType: PropTypes.oneOf(Object.values(StreamTypes)),
startTime: PropTypes.number,
startLevel: PropTypes.number,
};

export default MuxVideo;
8 changes: 6 additions & 2 deletions packages/playback-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,14 @@ function useNative(

export const setupHls = (
props: Partial<
Pick<MuxMediaPropsInternal, 'debug' | 'streamType' | 'type' | 'startTime' | 'metadata' | 'preferCmcd'>
Pick<
MuxMediaPropsInternal,
'debug' | 'streamType' | 'type' | 'startTime' | 'metadata' | 'preferCmcd' | 'startLevel'
>
>,
mediaEl: Pick<HTMLMediaElement, 'canPlayType'>
) => {
const { debug, streamType, startTime: startPosition = -1, metadata, preferCmcd } = props;
const { debug, streamType, startTime: startPosition = -1, metadata, preferCmcd, startLevel } = props;
const type = getType(props);
const hlsType = type === ExtensionMimeTypeMap.M3U8;
const shouldUseNative = useNative(props, mediaEl);
Expand Down Expand Up @@ -403,6 +406,7 @@ export const setupHls = (
debug,
startPosition,
cmcd,
startLevel,
...defaultConfig,
...streamTypeConfig,
}) as HlsInterface;
Expand Down
1 change: 1 addition & 0 deletions packages/playback-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export type MuxMediaPropTypes = {
autoplay?: Autoplay;
preferCmcd: ValueOf<CmcdTypes> | undefined;
error?: HTMLMediaElement['error'] | MediaError;
startLevel?: number;
};

export interface MediaTracks {
Expand Down
15 changes: 15 additions & 0 deletions packages/playback-core/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,20 @@ describe('playback core', function () {
assert(Number.isNaN(getTargetLiveWindow(mediaEl)), 'should have a default targetLiveWindow of NaN');
assert(Number.isNaN(getLiveEdgeStart(mediaEl)), 'should have a default liveEdgeStart of NaN');
});

it('should set startLevel', async function () {
const START_LEVEL = 100;

const video = document.createElement('video');
const core = initialize(
{
src: 'https://stream.mux.com/23s11nz72DsoN657h4314PjKKjsF2JG33eBQQt6B95I.m3u8',
startLevel: START_LEVEL,
},
video
);

assert.equal(core.engine.startLevel, START_LEVEL);
});
});
});