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: inferred stream type #592

Merged
merged 55 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
97b9762
feat(stream-type): Infer stream type in playback core (hls.js only).
cjpillsbury Feb 14, 2023
406c430
feat(mux-video): Add inferred streamType to mux-video.
cjpillsbury Feb 14, 2023
194b3b5
feat(mux-player): Temporarily strip out externally set stream type crud.
cjpillsbury Feb 14, 2023
c2a74bf
feat(playback-core): infer for native playback case as well.
cjpillsbury Feb 14, 2023
6b272ff
chore: Remove streamType from media-assets for now for testing.
cjpillsbury Feb 14, 2023
8696684
feat(playback-core, mux-video): Initial pass at targetLiveWindow impl…
cjpillsbury Feb 14, 2023
17ed4a3
feat(playback-core): Ensure streamtypechange and targetlivewindowchan…
cjpillsbury Feb 15, 2023
63a6e16
feat(playback-core, mux-video): Add liveEdgeStart support.
cjpillsbury Feb 17, 2023
5c00897
chore(mux-player): comment out logging for expected externally set st…
cjpillsbury Feb 27, 2023
edd3cba
chore(playback-core): Minor code cleanup.
cjpillsbury Feb 27, 2023
e8f94f8
fix(mux-player): Refactor storyboard for new inferred stream type. En…
cjpillsbury Feb 27, 2023
e2759a5
fix(playback-core): use number instead of Number for targetLiveWindow…
cjpillsbury Feb 27, 2023
547c262
feat(mux-video): Add basic setters for new m-ui-ext APIs (as overrides).
cjpillsbury Feb 27, 2023
9b03fb3
chore: Don't set streamType based on media asset selection in NextJS …
cjpillsbury Feb 28, 2023
dd05188
feat(mux-player, mux-video, playback-core): Re-adding explicit settin…
cjpillsbury Feb 28, 2023
6864ce5
test(mux-player): Update player tests that should now wait for stream…
cjpillsbury Feb 28, 2023
c50bc48
feat(playback-core, mux-player): hande live edge for native playback.…
cjpillsbury Mar 1, 2023
a04daf9
fix(playback-core): Respect preload none for stream info fetching in …
cjpillsbury Mar 2, 2023
a02cbef
test(mux-player): improve reliability of wait time for seek to live t…
cjpillsbury Mar 3, 2023
40a4080
test(mux-player): Update seek live tests for reliability of test cond…
cjpillsbury Mar 3, 2023
a2ddc5a
feat(mux-video, mux-player): Use external castable-video with new m-u…
cjpillsbury Mar 7, 2023
bc0b739
chore: clean up nextjs example to fully remove explicit stream type f…
cjpillsbury Mar 7, 2023
13e69e8
chore: Various code cleanup based on no longer needed code with infer…
cjpillsbury Mar 7, 2023
087f72a
feat(mux-player): Add liveEdgeStart getter to mux-player just in case…
cjpillsbury Mar 7, 2023
10ecbce
feat(mux-player-react): Add new props to ts defs.
cjpillsbury Mar 7, 2023
2e15450
docs(mux-player, mux-player-react): Update docs including error docs …
cjpillsbury Mar 7, 2023
a49e7a7
chore: Update nextjs MuxPlayer example to add enums for new stream ty…
cjpillsbury Mar 7, 2023
7f18442
fix(mux-player): Clean up relationships between deprecated stream typ…
cjpillsbury Mar 9, 2023
79df569
fix(mux-player): Do not automatically seek to live on play for DVR.
cjpillsbury Mar 9, 2023
faabf3e
docs(mux-video): Update mux video docs.
cjpillsbury Mar 9, 2023
6f95499
chore: Add deprecated stream type error md.
cjpillsbury Mar 9, 2023
c54171d
test(mux-player): Tighten no seek on play condition and update templa…
cjpillsbury Mar 9, 2023
34fb11d
fix(mux-player): tweak no seek to live condition for inferred stream …
cjpillsbury Mar 9, 2023
62d055d
Update errors/invalid-stream-type.md
cjpillsbury Mar 9, 2023
5273356
Update packages/mux-player/src/index.ts
cjpillsbury Mar 9, 2023
a2a65a4
Update packages/mux-video/src/index.ts
cjpillsbury Mar 9, 2023
82eb475
chore(mux-player): Simplify live stream type checks.
cjpillsbury Mar 20, 2023
5b5547f
fix(mux-player): liveEdgeStart not liveEdgeOffset.
cjpillsbury Mar 20, 2023
9a66246
chore(playback-core): code cleanup.
cjpillsbury Mar 20, 2023
e9ad032
chore(playback-core): Simplify live stream type checks.
cjpillsbury Mar 20, 2023
9c07d36
chore(playback-core): Break up functions for stream info (needs more …
cjpillsbury Mar 22, 2023
8cd29d3
chore(mux-player): Update tests and code for new template props and o…
cjpillsbury Apr 10, 2023
a3eed63
test(mux-video): Update order of events in playback-core for ease of …
cjpillsbury Apr 10, 2023
62342af
feat(mux-video): Use adjusted seekable on mux-video. Add test.
cjpillsbury Apr 10, 2023
13fa3e3
chore(playback-core): Manually re-apply abr adjustments for ll-hls (p…
cjpillsbury Apr 10, 2023
1593473
chore(mux-player): Don't log errors or warnings for deprecated stream…
cjpillsbury Apr 10, 2023
1ae06bf
fix(mux-player): Ensure noautoseeklive is properly respected on theme…
cjpillsbury Apr 10, 2023
abc38f3
docs(mux-player, mux-player-react): update docs to presume old stream…
cjpillsbury Apr 10, 2023
3b67a68
docs(mux-video): Move stream type usage to advanced section.
cjpillsbury Apr 10, 2023
1179dc1
Update packages/mux-player/src/index.ts
cjpillsbury Apr 12, 2023
aeae31c
Update packages/mux-video/src/index.ts
cjpillsbury Apr 12, 2023
337ab48
Update packages/mux-player/src/index.ts
cjpillsbury Apr 12, 2023
4d60639
chore(playback-core, mux-video, mux-player): Minor refactors per PR f…
cjpillsbury Apr 12, 2023
33e1016
fix(mux-player): For now, always force targetLiveWindow update based …
cjpillsbury Apr 12, 2023
48f18d5
Merge branch 'main' into feat/inferred-stream-type
cjpillsbury Apr 12, 2023
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
23 changes: 23 additions & 0 deletions errors/deprecated-stream-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Deprecated Stream Type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(non-blocking) -- open to other opinions.

Can we put this on a branch for safe keeping? Feels weird to have it in the repo if it's never linked.

Might also want to put the commented code on a branch. Feels a little sloppy to have commented out code making it into main


#### Why This Error Occurred

The provided `stream-type` is deprecated.

#### Possible Ways to Fix It

If you are a viewer of this video there is not much you can do. The owner of the
video will have to fix this issue.

If you are the owner of this video, `stream-type` can now be inferred based on the `playback-id` and is
no longer required. However, if you would still like to explicitly declare the `stream-type` (e.g. to
avoid an initial render of the wrong UI), here are the recommended refactors:

- `stream-type="ll-live"` - Replace with `stream-type="live"` (we will infer that the `playback-id` is low latency HLS)
- `stream-type="live:dvr"` or `stream-type="ll-live:dvr"` - Refactor as `stream-type="live"` & `target-live-window="Infinity"`

### Useful Links

- [Mux Player Attributes](https://github.com/muxinc/elements/tree/main/packages/mux-player#attributes)
- [Mux Player React Props](https://github.com/muxinc/elements/tree/main/packages/mux-player-react#props)
- [Play your videos](https://docs.mux.com/guides/video/play-your-videos)
6 changes: 4 additions & 2 deletions errors/invalid-stream-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ The provided `stream-type` is invalid.
If you are a viewer of this video there is not much you can do. The owner of the
video will have to fix this issue.

If you are the owner of this video make sure the `stream-type` is one of the
following: `on-demand`, `live`, `ll-live`, `live:dvr`, or `ll-live:dvr`.
If you are the owner of this video, `stream-type` is no longer required, so you may consider removing it.
If you still have a use case where you would like to explicitly define the `stream-type`, make sure the `stream-type` or
`default-stream-type` attribute is one of the following: `on-demand`, `live`.

### Useful Links

- [Mux Player Attributes](https://github.com/muxinc/elements/tree/main/packages/mux-player#attributes)
- [Mux Player React Props](https://github.com/muxinc/elements/tree/main/packages/mux-player-react#props)
- [Deprecated Stream Types](https://github.com/muxinc/elements/tree/main/errors/deprecated-stream-type)
- [Play your videos](https://docs.mux.com/guides/video/play-your-videos)
18 changes: 14 additions & 4 deletions examples/nextjs-with-typescript/components/renderers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fragment } from "react";
import { Fragment, ReactNode } from "react";

export const toWordsFromCamel = (string: string) => {
const first = string[0].toUpperCase();
Expand Down Expand Up @@ -116,13 +116,23 @@ export const ColorRenderer = ({
);
};

/** @TODO Consider refactoring to an actual react (functional) component (CJP) */
export const DefaultEnumFormatter = (enumValue) => {
let renderValue = JSON.stringify(enumValue);
if (renderValue === 'null' && enumValue !== null) {
renderValue = enumValue?.toString();
}
return <code>{renderValue}</code>;
};

export const EnumRenderer = ({
name,
value,
label,
onChange,
values,
}: { name: string; value: any | undefined; label?: string; onChange: (obj: any) => void; values: any[] }) => {
formatter = DefaultEnumFormatter
}: { name: string; value: any | undefined; label?: string; onChange: (obj: any) => void; values: any[], formatter?: (enumValue: any) => ReactNode }) => {
const labelStr = label ?? toWordsFromCamel(name);
return (
<div style={{ display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
Expand All @@ -142,10 +152,10 @@ export const EnumRenderer = ({
id={`${name}-${enumValue}-control`}
type="radio"
onChange={() => onChange({ [name]: values[i] })}
value={enumValue}
value={typeof enumValue === 'string' ? enumValue : enumValue?.toString()}
checked={value === enumValue}
/>
<label htmlFor={`${name}-${enumValue}-control`}><code>{JSON.stringify(enumValue)}</code></label>
<label htmlFor={`${name}-${enumValue}-control`}>{formatter(enumValue)}</label>
</Fragment>
)
})}
Expand Down
25 changes: 19 additions & 6 deletions examples/nextjs-with-typescript/pages/MuxPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@mux/mux-player/themes/minimal";
import "@mux/mux-player/themes/microvideo";
import { useEffect, useReducer, useRef, useState } from "react";
import mediaAssetsJSON from "@mux/assets/media-assets.json";
import type MuxPlayerElement from "@mux/mux-player";
import { useRouter } from "next/router";
import type { NextParsedUrlQuery } from "next/dist/server/request-meta";
import type { GetServerSideProps } from "next";
Expand Down Expand Up @@ -42,21 +41,17 @@ const toMetadataFromMediaAsset = (mediaAsset: typeof mediaAssetsJSON[0], mediaAs
const toPlayerPropsFromJSON = (mediaAsset: typeof mediaAssetsJSON[0] | undefined, mediaAssets: typeof mediaAssetsJSON) => {
const {
'playback-id': playbackId,
// 'stream-type': streamType,
tokens,
'custom-domain': customDomain,
'storyboard-src': storyboardSrc,
audio,
description: title,
placeholder,
} = mediaAsset ?? {};
// NOTE: Inferred type is "string" from JSON (CJP)
const streamType = mediaAsset?.['stream-type'] as MuxPlayerProps["streamType"];
const metadata = mediaAsset ? toMetadataFromMediaAsset(mediaAsset, mediaAssets) : undefined;

return {
playbackId,
streamType,
audio,
tokens,
customDomain,
Expand Down Expand Up @@ -360,6 +355,8 @@ function MuxPlayerPage({ location }: Props) {
maxResolution={state.maxResolution}
preload={state.preload}
streamType={state.streamType}
targetLiveWindow={state.targetLiveWindow}
defaultStreamType={state.defaultStreamType}
audio={state.audio}
primaryColor={state.primaryColor}
secondaryColor={state.secondaryColor}
Expand Down Expand Up @@ -423,7 +420,23 @@ function MuxPlayerPage({ location }: Props) {
value={state.streamType}
name="streamType"
onChange={genericOnChange}
values={['on-demand', 'live', 'll-live', 'live:dvr', 'll-live:dvr']}
values={['on-demand', 'live', 'll-live', 'live:dvr', 'll-live:dvr', 'unknown']}
formatter={(enumValue) => ['on-demand', 'live', 'unknown'].includes(enumValue)
? <code>{JSON.stringify(enumValue)}</code>
: <><code>{JSON.stringify(enumValue)}</code> (deprecated)</>
}
/>
<EnumRenderer
value={state.targetLiveWindow}
name="targetLiveWindow"
onChange={genericOnChange}
values={[Infinity, 0, NaN]}
/>
<EnumRenderer
value={state.defaultStreamType}
name="defaultStreamType"
onChange={genericOnChange}
values={['on-demand', 'live', 'unknown']}
/>
<EnumRenderer
value={getPlayerSize(stylesState.width)}
Expand Down
4 changes: 4 additions & 0 deletions packages/mux-player-react/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
| `disableCookies` | `boolean` | Disables cookies used by Mux Data. For more, check out the [Mux Docs](https://docs.mux.com/guides/data/monitor-html5-video-element#disable-cookies). | `false` |
| `storyboardSrc` | `string` (URL) | Full URL string for the storyboard asset. Typically derived from the `playbackId`, setting this attribute will override the derived storyboard. | `undefined` |
| `streamType` | `"on-demand" \| "live" \| "ll-live" \| "live:dvr" \| "ll-live:dvr"` | The type of stream associated with your Mux Asset. Used to determine what UI/controls to show and what optimizations to make for playback. | `"on-demand"` |
| `defaultStreamType` | `"on-demand" \| "live"` | The default assumed `streamType` before any `playbackId` has been loaded. Used along with `targetLiveWindow` to determine what UI/controls to show by default. | `on-demand` |
| `targetLiveWindow` | `number`| An offset representing the seekable range for live content, where `Infinity` means the entire live content is seekable (aka "standard DVR"). Used along with `streamType` to determine what UI/controls to show. | (inferred from `playbackId` and/or `streamType`, otherwise `NaN`) |
| `startTime` | `number` (seconds) | Specify where in the media's timeline you want playback to start. | `0` |
| `preferPlayback` | `"mse" \| "native"` | Specify if Mux Player should try to use Media Source Extension or native playback (if available). If no value is provided, Mux Player will choose based on what's deemed optimal for content and playback environment. | Varies |
| `maxResolution` | `"720p"` | Specify the max-resolution you want delivered for this video. The only valid option is the string `720p` | "" |
Expand All @@ -41,6 +43,8 @@
| `ref` | [React `ref`](https://reactjs.org/docs/refs-and-the-dom.html) | A [React `ref`](https://reactjs.org/docs/refs-and-the-dom.html) to the underlying [`MuxPlayerElement`](../mux-player/REFERENCE.md) web component | `undefined` |

<!-- UNDOCUMENTED
// NEW STREAM TYPE VALUES
| `streamType` | `"on-demand" \| "live" \| "unknown"` | The type of stream associated with your Mux Asset. Used along with `targetLiveWindow` to determine what UI/controls to show. | (inferred from `playbackId`, otherwise `"unknown"`) |
| `preferCmcd` | `"query" \| "header"` | Preference for how CMCD data is sent provided in Mux Video requests. Defaults to query params for performance. | `"query"` |
| `experimentalCmcd` | `boolean` | Enables CMCD usage for media asset requests (playlists, segments). | `false` |
| `playsInline` | `boolean` | Identical to the native `playsInline` property (property equivalent to [`<video playsinline/>` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-playsinline) | `false` |
Expand Down
5 changes: 4 additions & 1 deletion packages/mux-player-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ type MuxMediaPropTypes = {
customDomain: string;
playbackId: string;
preferPlayback: ValueOf<PlaybackTypes> | undefined;
streamType: ValueOf<StreamTypes> | 'vod';
// NOTE: Explicitly adding deprecated values here for now to avoid fully breaking changes in TS envs (CJP)
streamType: ValueOf<StreamTypes> | 'll-live' | 'live:dvr' | 'll-live:dvr';
defaultStreamType: ValueOf<StreamTypes>;
targetLiveWindow: number;
startTime: number;
storyboardSrc: string;
preferCmcd: ValueOf<CmcdTypes> | undefined;
Expand Down
1 change: 0 additions & 1 deletion packages/mux-player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ yarn add @mux/mux-player
playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"
metadata-video-title="Big Buck Bunny"
metadata-viewer-user-id="user-id-1234"
stream-type="on-demand"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh yeah!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless figuring out how to handle the pre-metadata loading UI is a blocker for this PR, I think we should probably keep documentation mentioning that stream-type is required.

Also, I don't think it should be a blocker, this way, we can get this PR in good shape and merge and then allow us to figure out the UI stuff in a follow-up PR.

></mux-player>
```

Expand Down
Loading