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

MPEG-DASH Support #2690

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5c611fd
Partial MPD support
Ponywka Apr 22, 2022
1dca9c5
mpd: remove unnecessary code
Ponywka Apr 22, 2022
25955c6
mpd: Update current quality logic
Ponywka Apr 22, 2022
1c6bbb5
mpd: Video track change
Ponywka Apr 22, 2022
e7b7f88
mpd: Events for track change
Ponywka Apr 22, 2022
c6e9ed6
mpd: Label support and tracks without `id`
Ponywka Apr 23, 2022
231bbfe
mpd: Refactor some functions
Ponywka Apr 23, 2022
bc93372
mpd: Add MPD support to `ads` plugin
Ponywka Apr 23, 2022
8086e93
mpd: Remove caption setup call when MPD
Ponywka Apr 23, 2022
4f8c0ac
mpd: Labels for tracks
Ponywka Apr 23, 2022
de09dcf
mpd: playsinline
Ponywka Apr 23, 2022
9b93194
mpd: Support for int `id`
Ponywka Apr 23, 2022
68a4b56
mpd: Disable AirPlay support (DASH.js incompatible)
Ponywka Apr 23, 2022
87a0534
mpd: Choosing the best bitrate
Ponywka Apr 23, 2022
9dda8c9
mpd: `audioTrackLabel.mpdLabels` to `audioTrackMPDLabel`
Ponywka Apr 23, 2022
44449f6
mpd: Remove `forced` from `audioTrack` & `videoTrack`
Ponywka Apr 23, 2022
232b485
mpd: `(e)=>{return !is.empty(e)}` to `e => e`
Ponywka Apr 23, 2022
f13b1e1
mpd: Changing some comments
Ponywka Apr 23, 2022
3735316
mpd: Add values to `.ts` file
Ponywka Apr 23, 2022
f27b5b9
mpd: Add some comments
Ponywka Apr 23, 2022
2c67dba
mpd: Add comments to `mpd.js` file
Ponywka Apr 23, 2022
fa4d223
mpd: Little refactoring
Ponywka Apr 23, 2022
8f6bffe
mpd: Remove dirty hack from switch-case construction
Ponywka Apr 23, 2022
a683e13
mpd: Lint all changed files
Ponywka Apr 23, 2022
6f95c16
mpd: Replace some `for` to `Array.prototype.find`
Ponywka Apr 23, 2022
36a9897
mpd: Replace some `for` to `Array.prototype.forEach`
Ponywka Apr 23, 2022
3ce2cec
mpd: Remove `try-catch`
Ponywka Apr 23, 2022
e6a64b7
mpd: Replace `for` to `find`
Ponywka Apr 23, 2022
decdb95
mpd: Remove dirty hack in `quality` config
Ponywka Apr 23, 2022
635ea23
mpd: Config overwrites
Ponywka Apr 23, 2022
a88bc91
mpd: `2147483647` to `qualityAutoMagicValue`
Ponywka Apr 23, 2022
6ec4a36
mpd: Why didn't anyone tell me about this before?
Ponywka Apr 24, 2022
671f42a
mpd: Why didn't anyone tell me about this before? x2
Ponywka Apr 24, 2022
9a4db8c
mpd: MPEG-DASH in main page
Ponywka May 7, 2022
f791f02
mpd: `sources.change` support
Ponywka May 7, 2022
57fc94f
mpd: Change caption tracks
Ponywka May 7, 2022
964830c
mpd: Syntax fix
Ponywka May 7, 2022
354245d
mpd: Another Dash.JS CDN
Ponywka May 7, 2022
29eb53e
mpd: Move "Auto" to bottom
Ponywka May 7, 2022
e8dc3f8
mpd: Move "Auto" to bottom x2
Ponywka May 7, 2022
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
37 changes: 36 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
href="https://cdn.plyr.io/static/fonts/gordita-bold.woff2"
/>

<!-- MPEG-DASH -->
<script src="https://cdn.dashjs.org/latest/dash.all.min.js"></script>

<!-- Google Analytics-->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-132699580-1"></script>
<script>
Expand Down Expand Up @@ -92,7 +95,7 @@ <h1>Pl<span>a</span>y<span>e</span>r</h1>
></path></svg
>YouTube
</button>
and
,
<button type="button" class="faux-link" data-source="vimeo">
<svg class="icon" role="presentation">
<title>Vimeo</title>
Expand All @@ -103,6 +106,21 @@ <h1>Pl<span>a</span>y<span>e</span>r</h1>
></path></svg
>Vimeo
</button>
and
<button type="button" class="faux-link" data-source="mpd">
<svg class="icon" role="presentation"><title>MPEG-DASH</title>
<path d="M0,2.16h4.85v5.21h-4.85Z" />
<path d="M11.15,2.16h4.85v5.21h-4.85Z" />
<path d="M5.57,2.16h4.85v5.21h-4.85Z" />
<path d="M0,8.09h4.85v3.06h-4.85Z" />
<path d="M11.15,8.09h4.85v3.06h-4.85Z" />
<path d="M5.57,8.09h4.85v3.06h-4.85Z" />
<path d="M0,11.87h4.85v1.98h-4.85Z" />
<path d="M11.15,11.87h4.85v1.98h-4.85Z" />
<path d="M5.57,11.87h4.85v1.98h-4.85Z" />
</svg>
MPEG-DASH
</button>
</p>

<div class="call-to-action">
Expand Down Expand Up @@ -229,6 +247,23 @@ <h1>Pl<span>a</span>y<span>e</span>r</h1>
</span>
</small>
</li>
<li class="plyr__cite plyr__cite--mpd" hidden>
<small>
<svg class="icon" role="presentation"><title>MPEG-DASH</title>
<path d="M0,2.16h4.85v5.21h-4.85Z" />
<path d="M11.15,2.16h4.85v5.21h-4.85Z" />
<path d="M5.57,2.16h4.85v5.21h-4.85Z" />
<path d="M0,8.09h4.85v3.06h-4.85Z" />
<path d="M11.15,8.09h4.85v3.06h-4.85Z" />
<path d="M5.57,8.09h4.85v3.06h-4.85Z" />
<path d="M0,11.87h4.85v1.98h-4.85Z" />
<path d="M11.15,11.87h4.85v1.98h-4.85Z" />
<path d="M5.57,11.87h4.85v1.98h-4.85Z" />
</svg>
<a href="https://mango.blender.org/" target="_blank">Tears of Steel</a>
&copy; Blender
</small>
</li>
</ul>
</main>
</div>
Expand Down
9 changes: 9 additions & 0 deletions demo/src/js/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ const sources = {
},
],
},
mpd: {
type: 'video',
sources: [
{
src: 'https://media.axprod.net/TestVectors/Cmaf/clear_1080p_h264/manifest.mpd',
provider: 'mpd',
},
],
},
};

export default sources;
16 changes: 12 additions & 4 deletions src/js/captions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const captions = {
}

// Only Vimeo and HTML5 video supported at this point
if (!this.isVideo || this.isYouTube || (this.isHTML5 && !support.textTracks)) {
if (!this.isVideo || this.isYouTube || ((this.isHTML5 || this.isMPD) && !support.textTracks)) {
// Clear menu and hide
if (
is.array(this.config.controls) &&
Expand Down Expand Up @@ -109,6 +109,9 @@ const captions = {
const trackEvents = this.config.captions.update ? 'addtrack removetrack' : 'removetrack';
on.call(this, this.media.textTracks, trackEvents, captions.update.bind(this));
}
if (this.isMPD) {
on.call(this, this.media.textTracks, 'addtrack removetrack', captions.update.bind(this));
}

// Update available languages in list next tick (the event must not be triggered before the listeners)
setTimeout(captions.update.bind(this), 0);
Expand All @@ -122,7 +125,7 @@ const captions = {
const languageExists = Boolean(tracks.find((track) => track.language === language));

// Handle tracks (add event listener and "pseudo"-default)
if (this.isHTML5 && this.isVideo) {
if ((this.isHTML5 || this.isMPD) && this.isVideo) {
tracks
.filter((track) => !meta.get(track))
.forEach((track) => {
Expand Down Expand Up @@ -276,10 +279,15 @@ const captions = {
triggerEvent.call(this, this.media, 'languagechange');
}

// Load captions for MPEG-DASH
if (this.isMPD) {
this.dash.setTextTrack(index);
}

// Show captions
captions.toggle.call(this, true, passive);

if (this.isHTML5 && this.isVideo) {
if ((this.isHTML5 || this.isMPD) && this.isVideo) {
// If we change the active track while a cue is already displayed we need to update it
captions.updateCues.call(this);
}
Expand Down Expand Up @@ -311,7 +319,7 @@ const captions = {
// For HTML5, use cache instead of current tracks when it exists (if captions.update is false)
// Filter out removed tracks and tracks that aren't captions/subtitles (for example metadata)
return tracks
.filter((track) => !this.isHTML5 || update || this.captions.meta.has(track))
.filter((track) => !this.isHTML5 || !this.isMPD || update || this.captions.meta.has(track))
.filter((track) => ['captions', 'subtitles'].includes(track.kind));
},

Expand Down
28 changes: 27 additions & 1 deletion src/js/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ const defaults = {
options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4],
},

// Audio Tracks (MPEG-DASH)
audioTrack: {
options: [],
onChange: null,
},

// Video Tracks (MPEG-DASH)
videoTrack: {
options: [],
onChange: null,
},

// Keyboard shortcut settings
keyboard: {
focused: true,
Expand Down Expand Up @@ -145,7 +157,7 @@ const defaults = {
// 'download',
'fullscreen',
],
settings: ['captions', 'quality', 'speed'],
settings: ['captions', 'quality', 'speed', 'audioTrack', 'videoTrack'],

// Localisation
i18n: {
Expand Down Expand Up @@ -174,6 +186,8 @@ const defaults = {
pip: 'PIP',
menuBack: 'Go back to previous menu',
speed: 'Speed',
audioTrack: 'Audio Track',
videoTrack: 'Video Track',
normal: 'Normal',
quality: 'Quality',
loop: 'Loop',
Expand All @@ -184,6 +198,7 @@ const defaults = {
disabled: 'Disabled',
enabled: 'Enabled',
advertisement: 'Ad',
qualityAuto: 'Auto',
qualityBadge: {
2160: '4K',
1440: 'HD',
Expand Down Expand Up @@ -274,6 +289,15 @@ const defaults = {
// Quality
'qualitychange',

// MPEG-DASH
'audiotrackchange',
'videotrackchange',
'qualitylistupdate',
'audiotracklistupdate',
'videotracklistupdate',
'audiotracklabelsupdate',
'videotracklabelsupdate',

// Ads
'adsloaded',
'adscontentpause',
Expand Down Expand Up @@ -317,6 +341,8 @@ const defaults = {
speed: '[data-plyr="speed"]',
language: '[data-plyr="language"]',
quality: '[data-plyr="quality"]',
audioTrack: '[data-plyr="audioTrack"]',
videoTrack: '[data-plyr="videoTrack"]',
},
display: {
currentTime: '.plyr__time--current',
Expand Down
1 change: 1 addition & 0 deletions src/js/config/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const providers = {
html5: 'html5',
youtube: 'youtube',
vimeo: 'vimeo',
mpd: 'mpd',
};

export const types = {
Expand Down
Loading