-
Notifications
You must be signed in to change notification settings - Fork 62
feat: Expose capLevelToPlayerSize property #1251
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
Changes from all commits
71d0528
556bf6c
3a6980c
3e53889
4099d8e
4cccc02
a6bfbda
7e65bc8
8f3139f
9295e24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,60 @@ export const BooleanRenderer = ({ | |
| ); | ||
| }; | ||
|
|
||
| export const OptionalBooleanRenderer = ({ | ||
| name, | ||
| value, | ||
| label, | ||
| onChange, | ||
| formatter = DefaultEnumFormatter | ||
| }: { | ||
| name: string; | ||
| value: boolean | undefined; | ||
| label?: string; | ||
| removeFalse?: boolean; | ||
| onChange: (obj: any) => void; | ||
| formatter?: (enumValue: boolean) => ReactNode; | ||
| }) => { | ||
| const labelStr = label ?? toWordsFromKeyName(name); | ||
| const values = [true, false]; | ||
| return ( | ||
| <div> | ||
| <label htmlFor={`${name}-control`}> | ||
| {labelStr} (<code>{name}</code>) | ||
| </label> | ||
| <div> | ||
| <input | ||
| id={`${name}-none-control`} | ||
| type="radio" | ||
| onChange={() => { | ||
| onChange(toChangeObject(name, undefined))}} | ||
| value="" | ||
| checked={value === undefined} | ||
| /> | ||
| <label htmlFor={`${name}-none-control`}>None</label> | ||
| {values.map((enumValue, i) => { | ||
| return ( | ||
| <Fragment key={`${name}-${enumValue}`}> | ||
| <input | ||
| id={`${name}-${enumValue}-control`} | ||
| type="radio" | ||
| onChange={() => { | ||
| const changeValue = enumValue; | ||
| console.log("Selecting value:", changeValue, toChangeObject(name, changeValue)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick(blocking): remove the console.log before merging |
||
| onChange(toChangeObject(name, changeValue)); | ||
| }} | ||
| value={enumValue.toString()} | ||
| checked={value === enumValue} | ||
| /> | ||
| <label htmlFor={`${name}-${enumValue}-control`}>{formatter(enumValue)}</label> | ||
| </Fragment> | ||
| ); | ||
| })} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export const NumberRenderer = ({ | ||
| name, | ||
| value, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,26 @@ | ||
| // @ts-nocheck | ||
| import Link from "next/link"; | ||
| import Head from "next/head"; | ||
| import "@mux/mux-player"; | ||
| import { useState } from "react"; | ||
| import { useRef, useState } from "react"; | ||
| import MuxPlayerElement from "@mux/mux-player"; | ||
| import { OptionalBooleanRenderer } from "../components/renderers"; | ||
| import { Autoplay, MuxMediaPropTypes } from "../../../packages/playback-core/dist/types/types"; | ||
|
|
||
| const INITIAL_DEBUG = false; | ||
| const INITIAL_MUTED = false; | ||
| const INITIAL_AUTOPLAY = false; | ||
| const INITIAL_MUTED = true; | ||
| const INITIAL_AUTOPLAY: Autoplay = false; | ||
| const INITIAL_PLAYBACK_ID = "g65IqSFtWdpGR100c2W8VUHrfIVWTNRen"; | ||
| const INITIAL_CAP_LEVEL_TO_PLAYER_SIZE : boolean | undefined = undefined; | ||
|
|
||
| function MuxPlayerWCPage() { | ||
| // const mediaElRef = useRef(null); | ||
| const mediaElRef = useRef<MuxPlayerElement>(null); | ||
| const [playbackId, setPlaybackId] = useState(INITIAL_PLAYBACK_ID); | ||
| const [muted, setMuted] = useState(INITIAL_MUTED); | ||
| const [debug, setDebug] = useState(INITIAL_DEBUG); | ||
| const [autoplay, setAutoplay] = useState(INITIAL_AUTOPLAY); | ||
| const debugObj = debug ? { debug: "" } : {}; | ||
| const mutedObj = muted ? { muted: "" } : {}; | ||
| const autoplayObj = autoplay ? { autoplay } : {}; | ||
| const [autoplay, setAutoplay] = useState<MuxMediaPropTypes["autoplay"]>(INITIAL_AUTOPLAY); | ||
| const [capLevelToPlayerSize, setCapLevelToPlayerSize] = useState<boolean | undefined>(INITIAL_CAP_LEVEL_TO_PLAYER_SIZE); | ||
| const debugObj : {debug?: boolean}= debug ? { debug: true } : {}; | ||
| const mutedObj : {muted?: boolean} = muted ? { muted: true } : {}; | ||
| const autoplayObj : {autoplay?: Autoplay} = autoplay ? { autoplay: autoplay } : {}; | ||
| return ( | ||
| <> | ||
| <Head> | ||
|
|
@@ -26,11 +29,13 @@ function MuxPlayerWCPage() { | |
|
|
||
| <div> | ||
| <mux-player | ||
| // style={{ aspectRatio: "16 / 9" }} | ||
| ref={mediaElRef} | ||
| playback-id={playbackId} | ||
| forward-seek-offset={10} | ||
| backward-seek-offset={10} | ||
| max-auto-resolution="720p" | ||
| cap-level-to-player-size={capLevelToPlayerSize ? true : undefined} | ||
| disable-cap-level-to-player-size={capLevelToPlayerSize === false ? true : undefined} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick(blocking): should this still exist? I thought we were descoping this for the initial implementation. |
||
| // onPlayerReady={() => console.log("ready!")} | ||
| {...debugObj} | ||
| {...mutedObj} | ||
|
|
@@ -43,13 +48,17 @@ function MuxPlayerWCPage() { | |
| ></mux-player> | ||
| </div> | ||
| <div className="options"> | ||
| <button onClick={() => { | ||
| if (!mediaElRef.current) return; | ||
| mediaElRef.current.load(); | ||
| }}>Reload</button> | ||
| <div> | ||
| <label htmlFor="autoplay-control">Muted Autoplay</label> | ||
| <input | ||
| id="autoplay-control" | ||
| type="checkbox" | ||
| onChange={() => setAutoplay(!autoplay ? "muted" : false)} | ||
| checked={autoplay} | ||
| checked={!!autoplay} | ||
| /> | ||
| </div> | ||
| <div> | ||
|
|
@@ -78,6 +87,11 @@ function MuxPlayerWCPage() { | |
| defaultValue={playbackId} | ||
| /> | ||
| </div> | ||
| <OptionalBooleanRenderer | ||
| value={capLevelToPlayerSize} | ||
| name="capLevelToPlayerSize" | ||
| onChange={({ capLevelToPlayerSize }) => setCapLevelToPlayerSize(capLevelToPlayerSize)} | ||
| /> | ||
| </div> | ||
| </> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,20 @@ | ||
| import Head from 'next/head'; | ||
| import { useRef, useState } from "react"; | ||
| import MuxVideo from "@mux/mux-video/react"; | ||
| import { EnumRenderer, OptionalBooleanRenderer } from '../components/renderers'; | ||
| import MuxVideoElement from '@mux/mux-video'; | ||
|
|
||
| const INITIAL_AUTOPLAY = false; | ||
| const INITIAL_MUTED = false; | ||
| const INITIAL_CAP_LEVEL_TO_PLAYER_SIZE : boolean | undefined = undefined; | ||
| const INITIAL_PREFER_PLAYBACK = undefined; | ||
|
|
||
| function MuxVideoPage() { | ||
| const mediaElRef = useRef(null); | ||
| const mediaElRef = useRef<MuxVideoElement>(null); | ||
| const [autoplay, setAutoplay] = useState<"muted" | boolean>(INITIAL_AUTOPLAY); | ||
| const [muted, setMuted] = useState(INITIAL_MUTED); | ||
| const [preferPlayback, setPreferPlayback] = useState<MuxVideoElement["preferPlayback"]>(INITIAL_PREFER_PLAYBACK); | ||
| const [capLevelToPlayerSize, setCapLevelToPlayerSize] = useState<boolean | undefined>(INITIAL_CAP_LEVEL_TO_PLAYER_SIZE); | ||
| const [paused, setPaused] = useState<boolean | undefined>(true); | ||
|
|
||
| return ( | ||
|
|
@@ -32,12 +38,14 @@ function MuxVideoPage() { | |
| // }} | ||
| // envKey="mux-data-env-key" | ||
| controls | ||
| capLevelToPlayerSize={capLevelToPlayerSize === true} | ||
| disableCapLevelToPlayerSize={capLevelToPlayerSize === false} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick(blocking): same as above |
||
| autoplay={autoplay} | ||
| muted={muted} | ||
| maxResolution="2160p" | ||
| minResolution="540p" | ||
| renditionOrder="desc" | ||
| preferPlayback="native" | ||
| preferPlayback={preferPlayback} | ||
| onPlay={() => { | ||
| setPaused(false); | ||
| }} | ||
|
|
@@ -47,6 +55,10 @@ function MuxVideoPage() { | |
| /> | ||
|
|
||
| <div className="options"> | ||
| <button onClick={() => { | ||
| if (!mediaElRef.current) return; | ||
| mediaElRef.current.load(); | ||
| }}>Reload</button> | ||
| <div> | ||
| <label htmlFor="paused-control">Paused</label> | ||
| <input | ||
|
|
@@ -74,6 +86,17 @@ function MuxVideoPage() { | |
| checked={muted} | ||
| /> | ||
| </div> | ||
| <EnumRenderer | ||
| value={preferPlayback} | ||
| name="preferPlayback" | ||
| onChange={({ preferPlayback }) => setPreferPlayback(preferPlayback as MuxVideoElement["preferPlayback"])} | ||
| values={['mse', 'native']} | ||
| /> | ||
| <OptionalBooleanRenderer | ||
| value={capLevelToPlayerSize} | ||
| name="capLevelToPlayerSize" | ||
| onChange={({ capLevelToPlayerSize }) => setCapLevelToPlayerSize(capLevelToPlayerSize)} | ||
| /> | ||
| </div> | ||
| </> | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: 😎 glad you acknowledged the "3rd state" of "optional booleans" (aka "unset")