3.2.4 • Published 3 days ago

ravnur-player-public v3.2.4

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
3 days ago

Ravnur Media Player Documentation

  1. Installation

  2. Initialization

  3. Setup

  4. Demo page

  5. Options

  6. Events

  7. Emits

  8. Methods

  9. Types (Flow syntax)

1. Installation

Using CDN

Include the Ravnur Media Player script in your HTML file by adding the following CDN link in the <head> section:

<script src="https://cdn.example.com/RavnurMediaPlayer.min.js"></script>

Add to Codebase

Alternatively, you can include the Ravnur Media Player script to your project's codebase. Ensure that you include the script in your HTML file:

<script src="path/to/RavnurMediaPlayer.min.js"></script>

Using private NPM registry

You can also install Ravnur Media Player using the npm private registry. If this is the right option for you, follow the steps below:

  1. Request an access token from the Ravnur administrator.
  2. Generate a base64 string using the provided token.
NPM_TOKENB64=$(echo -n '... your token here ...' | base64)
  1. Update your .npmrc file as shown below. You can leave username and email blank.
@ravnur:registry=https://ravnur.pkgs.visualstudio.com/Ravnur/_packaging/ravnur-npm/npm/registry/         
; begin auth token
//ravnur.pkgs.visualstudio.com/Ravnur/_packaging/ravnur-npm/npm/registry/:username=
//ravnur.pkgs.visualstudio.com/Ravnur/_packaging/ravnur-npm/npm/registry/:_password=${NPM_TOKENB64}
//ravnur.pkgs.visualstudio.com/Ravnur/_packaging/ravnur-npm/npm/registry/:email=
//ravnur.pkgs.visualstudio.com/Ravnur/_packaging/ravnur-npm/npm/:username=
//ravnur.pkgs.visualstudio.com/Ravnur/_packaging/ravnur-npm/npm/:_password=${NPM_TOKENB64}
//ravnur.pkgs.visualstudio.com/Ravnur/_packaging/ravnur-npm/npm/:email=
; end auth token
  1. Install Ravnur Player, ensuring that you specify the correct version.
npm install @ravnur/player@^3.1.1
  1. Include the player import in the file.
import RavnurPlayer from '@ravnur/player';

2. Initialization

To use Ravnur Media Player, initiate a new instance by providing the target element and styles:

// Replace 'yourElementId' with the ID of the HTML element where you want the player.
const element = document.getElementById('yourElementId');

// Object containing custom styling options (Optional)
const styles = { ... }; // Player$Styles type

// Initialize Ravnur Media Player
const player = new RavnurMediaPlayer(element, styles);

3. Setup

After initialization, set up the player with a video source and additional options.

// Object containing video source information. See Main Types section below.
let video = { ... }; // Player$Source type

// Object containing player options
let options = { ... };

player.setup(video, options); 

Demo page

https://strmsdemo.z13.web.core.windows.net/

Options

PropertyDefault valueTypeDescription
loggernullPlayer$LoggerCustom logger
loggerLevel2numberThis parameter sets the severity of logs.
i18nPlayer$TranslationCustom translations object
showPlaytruebooleanShows play button
showProgresstruebooleanShows progress bar
showVolumetruebooleanShows volume control
showFullScreentruebooleanShows full screen button
showTheaterModefalsebooleanShows theater mode button
showClosedCaptionstruebooleanShows captions
showTOCtruebooleanShows chapters
showAnnotationstruebooleanShows annotations
showQualitytruebooleanShows quality levels
showAudioTrackstruebooleanShows audio tracks
showPostertruebooleanShows poster image
showPlaceholdertruebooleanAdds play button as overlay
showPlaybackRatetruebooleanShows playback rate option in settings
showForwardtruebooleanShows 10 sec forward button
showBackwardtruebooleanShows 10 sec backward button
showSettingstruebooleanShows settings button
showDownloadtruebooleanShows download button
showTitletruebooleanShows media title
showNextFramefalsebooleanShows next frame button
showPrevFramefalsebooleanShows prev frame button
showCCLayouttruebooleanEnables caption layout option in CC settings
showPrev?falsebooleanShows next track button in full screen mode
showNext?falsebooleanShows prev track button in full screen mode
showCrawl?falsebooleanShows crawl text
crawlnullPlayer$CrawlOptionsCrawl text configurations
isProgressLiveStreamfalsebooleanIf true, disables progressbar click event and current time indicatior
useMuxfalsebooleanEnables MUX
showSubtitlesfalsebooleanDisables captions build in manifest
isAudiofalsebooleanTurns on players audio mode
timecode0numberSets time code value
frameRate23.976numberSets frame rate value
clipundefined[number, number]Plays part of the media
autoStartfalsebooleanEnables autoplay
startTimenullnumberSets media start time
endTimenullnumberSets media end time
useNativeControlsfalsebooleanRemoves all elements from the player and allows only native controls
useOriginTimeForPreviewtruebooleanEnables origin time frame for preview
playlistmodeautoPlayer$PlaylistModeControls playlist position
plalistAutoGoNexttruebooleanPlays next media when current ended
playlistitle''stringPlaylist title value
playlistforcepoint0numberMinimum width in pixels. If the player is resized to a width lower than this value, the playlist mode will be changed to 'bottom'.
playLoopfalsebooleanAutomatically starts playing from the beginning when the media has ended.
hideplaylistfalsebooleanHides playlist media previews
showExtensionstruebooleanShows custom extensions
alwaysShowExtensionstruebooleanKeeps showing extensions even if media is playing
extensionsVisibilityTimeout2000 ms on the desktop and 4000 ms on mobilenumberHides extensions if media is playing after this time.
skipDelta10numberValue in seconds which is used for media skip forward/backward functionality
keyboardListeners{}{ [keyCode]: (player) => void }List of key codes with custom handle functions
globalKeyboardListenersfalsebooleanControls whether keyboard events are listened to globally across the entire webpage or just within the specific player element
isHandlingKeyboardEventstruebooleanEnables keyboard event handling
bufferingTimeout200numberSpecifies the delay, in milliseconds, before displaying the processing spinner during buffering
hls{ maxFragLookUpTolerance: 0.001, maxMaxBufferLength: 60 }Player$HlsOptionsHls.js options
mux{ page_type: 'watchpage', player_name: 'RavnurPlayer', player_version: '1.0.0', video_stream_type: 'on-demand', }Player$MuxOptionsMux options
isMobiletrue on mobile devicesbooleanEnables mobile mode in the player
hlsjsURLhttps://cdn.jsdelivr.net/ hls.js/latest/hls.min.jsstringURL to specific hls.js version
flashPath/stringPath to specific Flash version
muxURLhttps://src.litix.io/ core/2/mux.jsstringPath to specific Mux version
savePlayTimefalsebooleanIf enabled, the player will save the last watched time in the browser's local storage. This allows the player to resume playback from the saved time during the next visit.
aesTokenundefinedstringAES Token value
playbackRatesundefinedArray of numbersCustom playback rate options: an array of numbers from 0.01 to 5. For example, [0.25, 0.50, 1, 1.75]. Option 1 is always present as "Standard", and option 5 is hidden for audio-only media.

Events

You can listen to player events using the player.on() method. Additionally, the player supports all HTMLMediaElement events. For details, refer to the MDN documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement

NameDataDescription
audiotrackswitchednullTriggered when the player changes audio tracks
handle-play-clickednullTriggered when the play button is clicked
theaterchangingnullTriggered when theater mode is changed
fullscreenchangingbooleanTriggered when full-screen mode changes
toclangstringTriggered when cue points language changes
cclangstringTriggered when captions language changes
annotationslangstringTriggered when annotations language changes
qualitychangestringTriggered when the quality level changes
resizeplayer{ width, height, outerWidth }Triggered when the player size changes
prevtracknullTriggered when switching to the previous track in the playlist
nexttracknullTriggered when switching to the next track in the playlist
mobiletouchnullTriggered on mobile touch events
downloadRequestedstringTriggered when someone requests media download, returns download URL
statechangedPlayer$StateTriggered when the player state changes
cclayoutchange{ mode, fontSize }Triggered when closed captions layout changes
captionschangePlayer$TimeDataSourceTriggered when captions change
changeplaylistmodebottom | rightTriggered when the player playlist mode changes
changesourcePlayer$SourceTriggered when the current media source changes

Emits

You have the option to manually trigger these events. For instance, you can use the following example: player.bus.emit('fullscreenchanging', false);

NamePayloadDescription
fullscreenchangingbooleanAlters full-screen mode
toclangstringModifies language for cue points
cclangstringModifies language for captions
annotationslangstringModifies language for annotations
prevtracknullSwitches to the previous media in the playlist
nexttracknullSwitches to the next media in the playlist
changeplaylistmodebottom | rightChanges the player's playlist mode
changesourcePlayer$SourceChanges the current media source

Methods

Example of usage: player.controller.getCurrentTime();.

MethodPayloadReturnDescription
getCurrentTime-numberRetrieves the current time of the media in seconds
setCurrentTimenumber-Sets the player's playback time
isPaused-booleanChecks if the media is currently paused
isEnded-booleanChecks if the media has reached the end
isMuted--Checks if the player is currently muted
play-PromiseInitiates playback of the media. Returns a Promise resolved when playback begins
pause--Pauses the current playback
prevFrame--Steps to the previous frame in the media
nextFrame--Steps to the next frame in the media
getDuration-numberRetrieves the duration of the media in seconds
setMutedboolean-Adjusts the muted state of the player
getVolume-numberRetrieves the current volume level
setVolumenumber-Sets the volume level of the player
getLevels-Array of objectsRetrieves the available quality levels
getLevel-ObjectRetrieves the current quality level
setLevelObject-Sets the quality level of the media
isMultiQuality-booleanChecks if the media has multiple quality options
isMultiAudioTracks-booleanChecks if the media has multiple audio tracks
getAudioTracks-Array of objectsRetrieves the available audio tracks
getAudioTrack-numberRetrieves the index of the current audio track
setAudioTracknumber-Sets the current audio track by index
loadPlayer$Source-Loads a new media source
getBufferedPercent-numberRetrieves the current buffered percentage
getElement-HTML elementRetrieves the player element
_getFrameDuration-numberRetrieves the current frame duration
refreshCrawlExtensioncrawl: Player$CrawlOptions, visibility: booleanRefreshes crawl options in the player
setPlaybackRatenumberSets the current playback rate

Types (Flow syntax)

type Player$LoggerFn = (...args: Array<mixed>) => void

type Player$Logger = {
   debug : Player$LoggerFn,
   log   : Player$LoggerFn,
   warn  : Player$LoggerFn,
   error : Player$LoggerFn
}

type Player$CrawlOptions = {
   text: string,
   speed: number,
   backgroundColor: string,
   textColor: string
}

type Player$PlaylistMode = 'bottom' | 'right' | 'auto';

 type Player$HlsOptions = {
   maxFragLookUpTolerance: number,
   maxMaxBufferLength: number
}

type Player$MuxOptions = {
   property_key: string,
   page_type: '' | 'watchpage' | 'iframe',
   viewer_user_id: string,
   experiment_name: string,
   sub_property_id: string,
   player_name: 'RavnurPlayer',
   player_version: string,
   player_init_time: number | null | '',
   video_id: string,
   video_title: string,
   video_series: string,
   video_producer: string,
   video_content_type: '' | 'short' | 'movie' | 'episode' | 'clip' | 'trailer' | 'event',
   video_language_code: string,
   video_variant_name: string,
   video_variant_id: string,
   video_duration: number | null | '',
   video_stream_type: 'live' | 'on-demand',
   video_encoding_variant: string,
   video_cdn: string
}

type Player$SourceStatus = 0 | 1 | 2;

type Player$TimeDataSource = {
   src: string,
   label: string,
   srclang: string,
   default?: boolean,
   type?: 'json' | 'vtt',
   state?: Player$SourceStatus
}

type Player$Source = {
   id: string;
   src: string,
   type: string,
   title: string,
   annotations?: Player$TimeDataSource[],
   chapters?: Player$TimeDataSource[],
   cc?: Player$TimeDataSource[],
   preview?: ?string,
   poster?: ?string,
   thumbnails?: ?string,
   clip?: ?[number, number] // [ 10, 300 ] sec
}

type Player$CCColor = '#F44336'
   | '#9C27B0' | '#3F51B5' | '#2196F3' | '#4CAF50'
   | '#FFEB3B' | '#FF9800' | '#795548' | '#9E9E9E' | '#FFF' | '#000'

type Player$CCFontSize = '75%' | '100%' | '125%' | '150%' | '200%'

type Player$CCFontFamily = '"Courier New", Courier, "Nimbus Mono L", "Cutive Mono", monospace'
   | '"Times New Roman", Times, Georgia, Cambria, "PT Serif Caption", serif'
   | '"Deja Vu Sans Mono", "Lucida Console", Monaco, Consolas, "PT Mono", monospace'
   | 'Roboto, "Arial Unicode Ms", Arial, Helvetica, Verdana, sans-serif'

type Player$CCLocation = 'over' | 'below'

type Player$StateCC = {
   color: Player$CCColor,
   bgcolor: Player$CCColor,
   fontSize: Player$CCFontSize,
   fontFamily: Player$CCFontFamily,
   location: Player$CCLocation,
   lang: ?string,
   sources: Player$TimeDataSource[],
   loading?: boolean,
   timedata: Player$TimeData[],
   timedataLang: string
}

type Player$StateTOC = {
   lang: ?string,
   sources: Player$TimeDataSource[],
   timedata: Player$TimeData[],
   timedataLang: string
}

type Player$State = {
   isFullScreen: boolean,
   isTheaterMode: boolean,
   cc: Player$StateCC,
   toc: Player$StateTOC
}

type Player$Styles = {
   accentColor: string,
   mainColor: string,
   submenuBgColor: string,
   submenuColor: string,
   chaptersBubbleColor: string,
   pltHeight: string,
   rplaylistHeight: string
}

 type Player$TimeData = {
   id: string,
   from: number,
   to: number,
   text: string,
   title?: ?string
}

type Player$Translation = {
   'fullscreen': string,
   'exit-fullscreen': string,
   'theater': string,
   'exit-theater': string,
   'play': string,
   'pause': string,
   'replay': string,
   'standard-playbackrate': string,
   'forward': string,
   'backward': string,
   'prevframe': string,
   'nextframe': string,
   'annotations': string,
   'quality': string,
   'audio-track': string,
   'playback-rate': string,
   'settings': string,
   'buffering': string,
   'cc': string,
   'chapters': string,
   'back': string,
   'settings-fontcolor': string,
   'settings-fontsize': string,
   'settings-fontfamily': string,
   'settings-background': string,
   'settings-captionlocations': string,
   'help': string,
   'download': string,
   'video-only': string,
   'video-and': string,
   'language': string,
   'unapproved-source': string,
   'translate': string,
   'translating': string,
   'monoserif'  : string,
   'propserif'  : string,
   'monosans'   : string,
   'propssans'  : string,
   'cc-location-over'    : string,
   'cc-location-below'   : string,
   'red'     : string,
   'purple'  : string,
   'indigo'  : string,
   'blue'    : string,
   'green'   : string,
   'yellow'  : string,
   'orange'  : string,
   'brown'   : string,
   'grey'    : string,
   'white'   : string,
   'black'   : string,
   'help-bacward'  : string,
   'help-play'     : string,
   'help-skip'     : string,
   'help-volume'   : string,
   'help-esc'      : string,
   'no-video'      : string,
   'no-flash'      : string,
   'playlist-count-of': string
}