Home Manual Reference Source Test
public class | source

Player

A class that wraps around HTMLMediaElement

It sends to the Host all relevant media events (ie: play, pause, etc)

This class should be extended in order to give provider specific support. By default all getter and setters interact with the media element, this can be overwritten by extending this class so it gets and sets by interacting with the relevant places for each provider.

Test:

Constructor Summary

Public Constructor
public

constructor(page: Page, host: Host, element: HTMLMediaElement)

Create a new instance of player

Member Summary

Public Members
public

A URL with the media baseURI It's updated in refresh whenever metadata changes

public

element: HTMLMediaElement

The media element

public

The Host to communicate with

public

The Page that holds the player

Method Summary

Public Methods
public

Get the artists of the player

public

Get the cover of the player.

public

Get the id of the player

public

Length is expected in microseconds by host

public

Get the current time of the media

public

Get the playback rate

public

Get the site domain (host)

public

Get the title of the player.

public

Get the elements url

public

If media is muted return 0

public

Add listeners on this.element so we propagate all necessary events to the this.host

public

Check if element is visible to the user

public

Is the media looping?

public

Is the media muted?

public

Returns true if the media is paused.

public

Returns true if the media is not paused

public

Return true if the media is paused and current time is 0.

public
public

pause()

Pause media element

public

play(): *

Play media element

public

If media is playing then pause else play it

public

Update this.URL so getter read the correct data.

public

seek(offset: number)

seek by an offset to position

public

setLoop(loop: boolean)

Should media loop when it reaches the end.

public

setPosition(position: number)

Set the position of playback

public

setRate(rate: number)

Set the playback rate

public

setVolume(volume: number)

Set the volume of the media

public

stop()

Pause media and set position to 0

public

Toogle the fullscreen state of the media.

Public Constructors

public constructor(page: Page, host: Host, element: HTMLMediaElement) source

Create a new instance of player

Params:

NameTypeAttributeDescription
page Page
host Host
element HTMLMediaElement

Public Members

public URL: Object source

A URL with the media baseURI It's updated in refresh whenever metadata changes

public element: HTMLMediaElement source

The media element

public host: Host source

The Host to communicate with

public page: Page source

The Page that holds the player

Public Methods

public getArtists(): Array<string> source

Get the artists of the player

Return:

Array<string>

Test:

public getCover(): string source

Get the cover of the player.

Using logo.clearbit.com API seems to work quite nicely. The other alternative is to get the logo from the page's favicon ({@link this.page.getIcon()})

Return:

string

Test:

public getId(): null | string source

Get the id of the player

Return:

null | string

the elements source

Test:

public getLength(): number source

Length is expected in microseconds by host

Return:

number

Test:

public getPosition(): number source

Get the current time of the media

Return:

number

media current time

public getRate(): number source

Get the playback rate

Return:

number

Test:

public getSiteDomain(): string source

Get the site domain (host)

Return:

string

public getTitle(): null | string source

Get the title of the player. The page's title by default.

Return:

null | string

Test:

public getUrl(): null | string source

Get the elements url

Return:

null | string

public getVolume(): number source

If media is muted return 0

Return:

number

Test:

public initDefaultMediaListeners() source

Add listeners on this.element so we propagate all necessary events to the this.host

public isHidden(): boolean source

Check if element is visible to the user

Return:

boolean

public isLooping(): boolean source

Is the media looping?

Return:

boolean

public isMuted(): boolean source

Is the media muted?

Return:

boolean

public isPaused(): boolean source

Returns true if the media is paused.

Return:

boolean

public isPlaying(): boolean source

Returns true if the media is not paused

Return:

boolean

Test:

public isStopped(): boolean source

Return true if the media is paused and current time is 0.

Return:

boolean

public isValid(): boolean source

Return:

boolean

public pause() source

Pause media element

public play(): * source

Play media element

Return:

*

public playPause() source

If media is playing then pause else play it

public refresh() source

Update this.URL so getter read the correct data. Also trigger a this.host.start event on the Host.

public seek(offset: number) source

seek by an offset to position

Params:

NameTypeAttributeDescription
offset number

offset to currentTime in microseconds

public setLoop(loop: boolean) source

Should media loop when it reaches the end.

Params:

NameTypeAttributeDescription
loop boolean

public setPosition(position: number) source

Set the position of playback

Params:

NameTypeAttributeDescription
position number

new currentTime in microseconds

public setRate(rate: number) source

Set the playback rate

Params:

NameTypeAttributeDescription
rate number

Test:

public setVolume(volume: number) source

Set the volume of the media

Params:

NameTypeAttributeDescription
volume number

Test:

public stop() source

Pause media and set position to 0

public toggleFullScreen() source

Toogle the fullscreen state of the media.

TODO:

  • test this works