Skip to content

Commit

Permalink
capricorn86#475@minor: Add currentTime and duration to HTMLMediaElement.
Browse files Browse the repository at this point in the history
  • Loading branch information
rudywaltz committed Jun 10, 2022
1 parent ce22cad commit 6f08a60
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
Expand Up @@ -13,6 +13,8 @@ import IHTMLMediaElement from './IHTMLMediaElement';
export default class HTMLMediaElement extends HTMLElement implements IHTMLMediaElement {
#volume = 1;
#paused = true;
#duration = NaN;
#currentTime = 0;
/**
* Returns autoplay.
*
Expand Down Expand Up @@ -158,6 +160,7 @@ export default class HTMLMediaElement extends HTMLElement implements IHTMLMediaE
DOMExceptionNameEnum.indexSizeError
);
}
// TODO: volumechange event https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/volumechange_event
this.#volume = parsedVolume;
}

Expand All @@ -177,7 +180,7 @@ export default class HTMLMediaElement extends HTMLElement implements IHTMLMediaE
*/
public set crossOrigin(crossOrigin: string | null) {
if (crossOrigin === null) {
return
return;
}

if (['', 'use-credentials', 'anonymous'].includes(crossOrigin)) {
Expand All @@ -196,6 +199,33 @@ export default class HTMLMediaElement extends HTMLElement implements IHTMLMediaE
return this.#paused;
}

/**
* Returns duration.
*
* @returns Duration.
*/
public get duration(): number {
return this.#duration;
}

/**
* Returns currentTime.
*
* @returns CurrentTime.
*/
public get currentTime(): number {
return this.#currentTime;
}

/**
* Sets currentTime.
*
* @param currentTime CurrentTime.
*/
public set currentTime(currentTime: number) {
this.#currentTime = currentTime;
}

/**
*
*/
Expand Down Expand Up @@ -226,6 +256,10 @@ export default class HTMLMediaElement extends HTMLElement implements IHTMLMediaE
* @param [deep=false] "true" to clone deep.
* @returns Cloned node.
*/
/**
*
* @param deep
*/
public cloneNode(deep = false): IHTMLMediaElement {
return <IHTMLMediaElement>super.cloneNode(deep);
}
Expand Down
Expand Up @@ -8,28 +8,26 @@ import IHTMLElement from '../html-element/IHTMLElement';
*/
export default interface IHTMLMediaElement extends IHTMLElement {
readonly currentSrc: string;
readonly duration: number;
autoplay: boolean;
controls: boolean;
loop: boolean;
muted: boolean;
paused: boolean; // TODO readonly?
paused: boolean;
volume: number | string;
src: string;
crossOrigin: string; // Only anonymus and 'use-credentials' is valid
currentTime: number;

// AddTextTrack;
// Buffered; // TODO
// Buffered; // TODO tameranges
// CaptureStream; // TODO
// ControlsList: string; // TODO
// CurrentSrc: string; // TODO
// CurrentTime; // TODO
// DefaultMuted: boolean; // TODO
// DefaultPlaybackRate; // TODO
// DisableRemotePlayback: boolean; // TODO
// Duration: number; // TODO
// Ended: boolean; // TODO readonly
// Error; // TODO object
// MediaKeys; // TODO
// NetworkState; // TODO
// Played: // TODO timeranges
// PlaybackRate: number; // TODO
Expand Down
Expand Up @@ -145,4 +145,20 @@ describe('HTMLMediaElement', () => {
expect(element.getAttribute('crossorigin')).toBe('anonymous');
});
});

describe('duration', () => {
it('Return 0 by default', () => {
expect(element.duration).toBe(NaN);
});
});

describe('currentTime', () => {
it('Return default value', () => {
expect(element.currentTime).toBe(0);
});
it('Set value', () => {
element.currentTime = 42;
expect(element.currentTime).toBe(42);
});
});
});

0 comments on commit 6f08a60

Please sign in to comment.