24.6.1-2-gd4ac37d • Published 10 months ago

@flussonic/flussonic-mse-player v24.6.1-2-gd4ac37d

Weekly downloads
108
License
ISC
Repository
github
Last release
10 months ago

flussonic-mse-player

flussonic-mse-player is a JavaScript library for playing video relies on flussonic backend, HTML5 video and MediaSource Extensions

Installation

npm install --save @flussonic/flussonic-mse-player

Usage

Webpack:

import FlussonicMsePlayer from '@flussonic/flussonic-mse-player'
...
const player = new FlussonicMsePlayer(element, url, opts)

example

Script tag:

Since the library include via script tag it is accesible at window.FlussonicMsePlayer

<script type="text/javascript" src="../../dist/FlussonicMsePlayer.js"></script>
var FlussonicMsePlayer = window.FlussonicMsePlayer
var player = new FlussonicMsePlayer(element, url, opts)

example

Static Methods:

  • isSupported() - return true if browser is supported Media Source Extension

  • replaceHttpByWS(url: string) - return new url where replaced http(s):// by ws(s)://

Construction:

const player = new FlussonicMsePlayer(element, url, opts)

element - DOM element

url - url of a stream

opts is plain object it can include methods:

  • debug?: boolean - if true then enable logs in browser console. And export methods humanTime, humanDate to window.

  • progressUpdateTime?: number - time period for invoking onProgress.

  • connectionRetries?: number - number of reconnection retries if player can't start playback.

  • wsReconnect?: boolean - trying to restart websocket connection on error closing.

  • preferHQ?: boolean - if true, player will automatically select the highest available quality of the stream.

  • retryMuted?: boolean - if true, in some cases, due to "Browser Autoplay Policy Changes" it will try to restart playing process with initialy muted video element.

  • maxBufferDelay?: number - maxBufferDelay option for sourceBuffer

  • onProgress(utc: number) - triggered every 100ms(progressUpdateTime) while a stream is playing and gives current playback time

  • onMediaInfo(info: MediaInfo) - triggered when metadata of the stream is available. metadata include a common information of the stream such as width, height, information about mbr streams and so on. After this callback triggered you can use getVideoTracks()/getAudioTracks() methods.

  • onDisconnect(status: object) - triggered on websocket connection lost.

  • onError(error: object) - triggered on player errors.

  • onEvent(event: object) - triggered on player events.

  • onMuted() - triggered on player set muted.

  • onPause() - triggered on player set paused.

  • onResume() - triggered on player gets resumed from pause.

  • onStats(stats: object) - triggered on player stats change. Stats include a common ststistics of the stream: endTime, currentTime, videoBuffer, audioBuffer, timestamp, readyState, networkState.

  • onSeeked() - triggered when process of seeking is finished

  • onStartStalling() - triggered when playing is stalled

  • onEndStalling() - triggered when the video tag is progressed(start playing). onStartStalling()/onEndStalling() useful callback for implementation loading-spinner.

  • •••DEPRECATED••• bufferMode: 'segments'|'sequence' - SourceBuffer Object Append Mode. Default value is 'sequence'.

  • errorsBeforeStop: number - Amount of errors will be happened before invoke the stop() method.

Methods:

  • play(videoTrack?: Track, audioTrack?: Track) => Promise - start playing.

    Return a Promise. Resolved if HTMLMediaElement.play() resolved(HTMLMediaElement.play() Returns a Promise). Overwise rejected with error message.

    if you do autoplay="true" muted="false" video. The play will be rejected(Autoplay Policy Changes)

    For resolve this behaviour you can mute the video before playing. Or you can process play's rejection and show play button.

  • pause() - send pause command by websocket

  • stop() - close websocket connection; detach mediaSource from given HTMLMediaElement; invoke the HTMLMediaElement stop method

  • restart() - perform a full restart of playing process

  • autoTrackSelection(preferBest: boolean) => tracks: Array - if true - returns array with the tracks of highest available quality. If false - returns array with the tracks of the lowest available quality.

  • seek(utc: number) - send seek command by websocket

  • setTracks(tracks: Array) -

Types:

type MediaInfo = {
  height: number,
  width: number,
  streams: Array<StreamInfo>,
  activeStreams: ActiveStreams,
}

type StreamInfo = {
  bitrate: number,
  codec: string,
  content: string,
  fps: number,
  height: number,
  length_size: number,
  level: string,
  pixel_height: number,
  pixel_width: number,
  profile: "Baseline",
  sar_height: number,
  sar_width: number,
  size: string,
  track_id: TrackId,
  width: number
}

type ActiveStreams = {
  video: TrackId,
  audio: TrackId,
}

type TrackId = 'a1'|'a2'|'a3'| ... 'aN'|'v1'|'v2'|'v3'| ... 'vN'

type UtcOrLive = number | 'live'

TODO

CHANGELOG

24.6.1-2-gd4ac37d

10 months ago

22.6.2

3 years ago

22.6.1

3 years ago

22.5.1

3 years ago

22.4.3

3 years ago

22.4.2

3 years ago

22.4.1

3 years ago

22.3.3

3 years ago

22.2.1

3 years ago

22.2.3

3 years ago

22.2.2

3 years ago

21.12.1

4 years ago

22.3.2

3 years ago

22.3.1

3 years ago

22.1.2

3 years ago

22.1.1

3 years ago

22.1.4

3 years ago

22.1.3

3 years ago

21.10.3

4 years ago

21.10.2

4 years ago

21.10.1

4 years ago

21.9.2

4 years ago

21.9.1

4 years ago

21.8.2

4 years ago

21.8.1

4 years ago

21.7.1

4 years ago

21.6.2

4 years ago

21.6.1

4 years ago

21.5.1

4 years ago

21.2.1

4 years ago

21.1.1

4 years ago

20.12.2

5 years ago

20.12.1

5 years ago

20.11.1

5 years ago

20.10.4

5 years ago

20.10.3

5 years ago

20.10.1

5 years ago

20.10.2

5 years ago

20.9.3

5 years ago

20.9.2

5 years ago

20.9.1

5 years ago

20.8.1

5 years ago

20.7.1

5 years ago

20.6.3

5 years ago

20.6.2

5 years ago

20.6.1

5 years ago

20.5.2

5 years ago

20.5.1

5 years ago

20.4.1

5 years ago

20.4.2

5 years ago

20.3.2

5 years ago

20.3.1

5 years ago

20.2.4

5 years ago

20.2.2

5 years ago

20.2.1

5 years ago

20.1.6

5 years ago

20.1.5

5 years ago

20.1.4

5 years ago

20.1.3

5 years ago

20.1.2

5 years ago

20.1.1

5 years ago

19.10.4

6 years ago

19.10.2

6 years ago

19.10.1

6 years ago

19.9.5

6 years ago

19.9.4

6 years ago

19.9.3

6 years ago

19.9.2

6 years ago

19.9.1

6 years ago

19.8.4

6 years ago

19.8.3

6 years ago

19.8.2

6 years ago

19.8.1

6 years ago

19.7.3

6 years ago

19.7.2

6 years ago

19.7.1

6 years ago

19.6.4

6 years ago

19.6.3

6 years ago

19.6.2

6 years ago

19.6.1

6 years ago

19.2.9

6 years ago

19.2.8

6 years ago

19.2.7

6 years ago

19.2.6

6 years ago

19.2.5

6 years ago

19.2.4

6 years ago

19.2.3

6 years ago

19.2.2

6 years ago

18.9.3

7 years ago

18.9.1

7 years ago

18.8.6

7 years ago

18.8.5

7 years ago

18.8.4

7 years ago

18.8.1

7 years ago

18.8.0

7 years ago

18.7.2

7 years ago

18.7.1

7 years ago

18.7.0

7 years ago

18.4.3

7 years ago

18.4.2

7 years ago

18.4.1

7 years ago

18.4.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago