0.3.6 • Published 6 months ago

@nomercy-entertainment/nomercy-video-player v0.3.6

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
6 months ago

NoMercy VideoPlayer

NoMercy VideoPlayer is a lightweight, plugin-based, customizable HTML5 video player built with JavaScript. It is designed to support a variety of media formats and streaming protocols while allowing developers to extend its functionality through modular plugins. Always feel like fighting video player UI choices? then this is the player for you.

Features

  • HTML5 Video Support: Compatible with popular media formats (MP4, WebM, Ogg).
  • Streaming Support: Handles streaming protocols like HLS via URLs.
  • Plugin-Based Architecture: UI, subtitle renderer, and key event handler are customizable plugins, enabling easy customization and flexibility.
  • Customizable Controls: Modify buttons, layout, and styles through plugins or custom code.
  • Subtitles & Captions: Full support for VTT and ASS subtitle formats.
  • Keyboard Shortcuts: Extendable key event handler for custom controls.

Example

import nmplayer from '@nomercy-entertainment/nomercy-video-player/src/index';
import OctopusPlugin from '@nomercy-entertainment/nomercy-video-player/src/plugins/octopusPlugin';
import KeyHandlerPlugin from '@nomercy-entertainment/nomercy-video-player/src/plugins/keyHandlerPlugin';
import type { PlayerConfig } from '@nomercy-entertainment/nomercy-video-player/src/types';

const config: PlayerConfig = {
	muted: false,
	controls: false,
	preload: 'auto',
	debug: false,
	playlist: [
		{
			title: 'Cosmos Laundromat',
			description: 'On a desolate island, a suicidal sheep named Franck meets his fate…',
			image: 'https://image.tmdb.org/t/p/w780/f2wABsgj2lIR2dkDEfBZX8p4Iyk.jpg',
			file: 'https://media.nomercy.tv/Films/Films/Cosmos.Laundromat.(2015)/Cosmos.Laundromat.(2015).NoMercy.m3u8',
			tracks: [
				{ label: 'Dutch (Full)', file: '...NoMercy.dut.full.vtt', language: 'dut', kind: 'subtitles' },
				{ label: 'English (Full)', file: '...NoMercy.eng.full.vtt', language: 'eng', kind: 'subtitles' },
				// Additional subtitle tracks...
			],
		},
		{
			title: 'Sintel',
			description: 'Sintel is an independently produced short film...',
			image: 'https://image.tmdb.org/t/p/w780/q2bVM5z90tCGbmXYtq2J38T5hSX.jpg',
			file: 'https://media.nomercy.tv/Films/Films/Sintel.(2010)/Sintel.(2010).NoMercy.m3u8',
			tracks: [
				{ label: 'Dutch (Full)', file: '...NoMercy.dut.full.vtt', language: 'dut', kind: 'subtitles' },
				{ label: 'English (Full)', file: '...NoMercy.eng.full.vtt', language: 'eng', kind: 'subtitles' },
				// Additional subtitle tracks...
			],
		},
		// Additional playlist items...
	],
	playbackRates: [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2],
    // Additional configuration options...
};

const player = nmplayer('player') // 'player' is the ID of the div element, do not use a video tag
	.setup(config);

// Bind VLC keyboad shortcuts
const keyHandlerPlugin = new KeyHandlerPlugin();
player.registerPlugin('keyHandler', keyHandlerPlugin);
player.usePlugin('keyHandler');

// ASS subtitle support
const octopusPlugin = new OctopusPlugin();
player.registerPlugin('octopus', octopusPlugin);
player.usePlugin('octopus');

// const customUIPlugin = new CustomUIPlugin();
// player.registerPlugin('customUI', customUIPlugin);
// player.usePlugin('customUI');

Plugin Development

Developers can create their own plugins by following the NoMercy VideoPlayer API. Here's a basic structure of a plugin:

import Plugin from '@nomercy-entertainment/nomercy-video-player/src/plugin';
import { NMPlayer } from '@nomercy-entertainment/nomercy-video-player/src/types';

export interface PluginArgs {
	// Your extra config items
}

class CustomUIPlugin extends Plugin {
	player: NMPlayer<PluginArgs> = NMPlayer < PluginArgs > {};

	initialize(player: NMPlayer<PluginArgs>) {
		this.player = player;
		// Setup your plugin before use is called
	}
	
	dispose() {
		// clean up, called when the plugin is unmounted or the player is disposed
	}

	use() {
		// plugin logic
	}
}

export default CustomUIPlugin;

Type Definitions for NoMercyVideoPlayer

note: type definitions and api may not be 100% correct and are subject to change.

Interfaces

PlayerConfig

Configuration options for the player.

PropertyTypeDescription
chaptersboolean\|undefinedEnables or disables chapter support.
playliststring\| PlaylistItem[]Playlist items or URL.
debugboolean\|undefinedEnables debug mode.
mutedboolean\|undefinedStarts playback in muted mode.
controlsboolean\|undefinedEnables or disables playback controls.
autoPlayboolean\|undefinedStarts playback automatically.
preloadAutoLoadOptons\|'none'Preload behavior for the media.
stretchingStretchOptions\|undefinedVideo stretching options.
playbackRatesnumber[]\|undefinedAvailable playback rates.
accessTokenstring\|undefinedAccess token for authentication.
basePathstring\|undefinedBase path for media files.
languagestring\|undefinedLanguage code for the UI.
displayLanguagestring\|undefinedLanguage for display.

StretchOptions

Options for video stretching.

ValueDescription
fillWhether to fill the container.
fitWhether to fit the container.
noneWhether to disable stretching.
exactfitWhether to fit exactly.

AutoLoadOptons

Options for media preload behavior.

ValueDescription
autoAutomatically preload the media.
metadataPreload metadata only.
noneDisable preload.

PlaylistItem

Represents a media playlist item.

PropertyTypeDescription
idstring\| numberUnique identifier for the playlist item.
progress{ time: number, date: string }\|undefinedProgress information with time and date.
durationstringTotal duration of the playlist item.
filestringURL or path to the media file.
imagestringURL or path to the thumbnail image.
titlestringTitle of the playlist item.
tracksTrack[]\|undefinedList of associated tracks.
descriptionstringDescription of the playlist item.
seasonnumber\|undefinedSeason number (if applicable).
episodenumber\|undefinedEpisode number (if applicable).

Track

Represents a media track.

PropertyTypeDescription
idnumberUnique identifier for the track.
defaultboolean\|undefinedWhether this is the default track.
filestringURL or path to the track file.
kindTrackTypeType of track.
labelstring\|undefinedLabel for the track.
languagestring\|undefinedLanguage of the track.
typestring\|undefinedAdditional type information for the track.
extstring\|undefinedFile extension for the track.

TrackType

Type of media track.

ValueDescription
subtitlesSubtitle track.
chaptersChapter track.
fontsFonts track.
thumbnailsDescription track.
spriteSprite track.

Methods

Playback and State Control
MethodParametersReturn TypeDescription
playbooleanPromise<void>Starts or resumes playback.
pausebooleanvoidPauses playback.
stopNonevoidStops playback.
seeknumbervoidSeeks to a specific position.
togglePlaybackNonevoidToggles between play and pause states.
setVolumenumbervoidSets the volume (0–1).
setMutebooleanvoidMutes or unmutes the player.
setPlaybackRatenumbervoidSets the playback speed.
getStateNonePlayStateGets the current playback state.
setupPlayerConfigNMPlayer<PlayerConfig>Initializes the player with options.
Quality and Track Management
MethodParametersReturn TypeDescription
getQualityLevelsNoneLevel[]Retrieves available quality levels.
setCurrentQualitynumbervoidSets the current quality level.
getAudioTracksNoneMediaPlaylist[]Retrieves available audio tracks.
cycleAudioTracksNonevoidCycles through audio tracks.
setCurrentAudioTracknumbervoidSets the current audio track.
getCaptionsListNoneTrack[]Retrieves available caption tracks.
cycleSubtitlesNonevoidCycles through subtitle tracks.
setCurrentCaptionnumbervoidSets the current subtitle track.
Player UI
MethodParametersReturn TypeDescription
enterFullscreenNonevoidEnters fullscreen mode.
exitFullscreenNonevoidExits fullscreen mode.
toggleFullscreenNonevoidToggles fullscreen mode.
Event Handling
MethodParametersReturn TypeDescription
emit(event: string, data?: any)voidEmits a custom event with optional data.
on(event: string, callback: Function)voidAdds a listener for a specific event.
off(event: string, callback: Function)voidRemoves a listener for a specific event.
once(event: string, callback: Function)voidAdds a one-time listener for an event.

Events

Event NameData TypeDescription
all-Triggered for all events.
audioTrackChangedCurrentTrackTriggered when the audio track changes.
audioTrackChangingCurrentTrackTriggered when the audio track is in the process of changing.
audioTracksTrack[]Triggered when the audio tracks list is updated.
back(arg?: any) => anyTriggered when the back button is pressed.
beforeplaylistitem-Triggered before a playlist item is played.
bufferChange-Triggered when the buffer state changes.
buffer-Triggered when buffering occurs.
bufferedEnd-Triggered when the buffered end is reached.
captionsChangedCurrentTrackTriggered when captions change.
captionsChangingCurrentTrackTriggered when captions are in the process of changing.
captionsListTrack[]Triggered when the captions list is updated.
chaptersVTTDataTriggered when the chapters data changes.
complete-Triggered when the media playback completes.
controls(showing: booleanTriggered when controls visibility changes.
display-messagestringTriggered when a message is displayed.
dispose-Triggered when the player is disposed of.
durationTimeDataTriggered when the duration data changes.
ended-Triggered when playback ends.
erroranyTriggered when an error occurs.
finished-Triggered when the entire playback session finishes.
firstFrame-Triggered when the first frame is displayed.
forwardnumberTriggered when fast-forwarding by a certain amount.
fullscreen(enabled: booleanTriggered when fullscreen state changes.
itemPlaylistItemTriggered when a playlist item is loaded.
lastTimeTriggerTimeDataTriggered when the last time trigger occurs.
levelsChangedCurrentTrackTriggered when levels change for the current track.
levelsChangingCurrentTrackTriggered when levels are in the process of changing.
levelsLevel[]Triggered when the levels change. See Hls.js
meta-Triggered when the metadata is updated.
muteVolumeStateTriggered when the mute state changes.
overlay-Triggered when an overlay is displayed.
pause-Triggered when playback is paused.
play-Triggered when playback starts.
playbackRateChanged-Triggered when the playback rate changes.
playing-Triggered when playback starts or resumes.
playlistComplete-Triggered when the playlist is complete.
playlistPlaylistItem[]Triggered when a playlist is loaded or changed.
playlistchange-Triggered when the playlist changes.
ready-Triggered when ready to start.
remove-messagestringTriggered when a message is removed.
remove-Triggered when the player is removed.
resize-Triggered when the player is resized.
rewindnumberTriggered when rewinding by a certain amount.
seek-Triggered when seeking starts.
seeked-Triggered when seeking ends.
setupError-Triggered when a setup error occurs.
skippersChapter[]Triggered when the chapter skippers list changes.
speednumberTriggered when the playback speed is changed.
stalled-Triggered when playback stalls.
timeTimeDataTriggered when the playback time updates.
translations{ [key: string]: string }Triggered when translations are loaded or changed.
volumeVolumeStateTriggered when the volume changes.
waiting-Triggered when the player is waiting for something.

CurrentTrack

Represents the currently selected media track.

PropertyTypeDescription
idnumberUnique identifier of the track.
namestringName of the track.

PreviewTime

Describes preview thumbnail dimensions and coordinates.

PropertyTypeDescription
startnumberStart time for the preview.
endnumberEnd time for the preview.
xnumberX-coordinate for the preview.
ynumberY-coordinate for the preview.
wnumberWidth of the preview area.
hnumberHeight of the preview area.

VolumeState

Represents the player's current volume state.

PropertyTypeDescription
mutedbooleanWhether the player is muted.
volumenumberCurrent volume level (0–1).

Chapter

Defines a chapter in the media.

PropertyTypeDescription
endTimenumberEnd time of the chapter in seconds.
idstringUnique identifier for the chapter.
leftnumberLeft position of the chapter marker.
startTimenumberStart time of the chapter in seconds.
timenumberDuration of the chapter in seconds.
titlestringTitle of the chapter.
widthnumberWidth of the chapter marker.

TimeData

Provides playback time information.

PropertyTypeDescription
currentTimenumberCurrent playback time in seconds.
durationnumberTotal duration of the media in seconds.
percentagenumberPercentage of media played (0–100).
remainingnumberTime remaining in seconds.
currentTimeHumannumberCurrent playback time in a human-readable format.
durationHumannumberTotal duration in a human-readable format.
remainingHumannumberRemaining time in a human-readable format.
playbackRatenumberCurrent playback rate (e.g., 1.0, 1.5).

Contributions

Contributions are welcome! If you encounter issues or have suggestions for improvement, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For further information or support, visit NoMercy.tv or contact our support team.

Made with ❤️ by NoMercy Entertainment

0.3.9

6 months ago

0.3.8

6 months ago

0.3.7

6 months ago

0.3.6

6 months ago

0.3.5

8 months ago

0.3.4

8 months ago

0.3.3

8 months ago

0.3.2

9 months ago

0.2.11

9 months ago

0.2.10

9 months ago

0.2.6

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.0

11 months ago