cycleSubtitles
player.cycleSubtitles(): void
Walks the subtitle track list in order: off → 0 → 1 → … → N-1 → off.
Each call activates the next track; when the end is reached it cycles back to off.
This method is designed for remote-control contexts (keyboard, TV D-pad) where the user cannot pick from a dropdown menu.
UI plugins that render a subtitle menu should call player.subtitle(idx) directly instead.
// Bind to a keyboard shortcut (the player has no 'keydown' event — use a DOM listener,
// or let KeyHandlerPlugin own the binding)
document.addEventListener('keydown', (event) => {
if (event.key === 'v') player.cycleSubtitles();
});
The KeyHandlerPlugin binds 'v', '5', and the 'Subtitle' media key to cycleSubtitles() by default.
Emits: 'subtitle' with the newly selected track index (or null when cycling to off).
cycleAudioTracks
player.cycleAudioTracks(): void
Walks the audio track list in order, wrapping around: 0 → 1 → … → N-1 → 0.
Useful when the source has multiple audio renditions (e.g. original language + dub).
The KeyHandlerPlugin binds 'b', '2', and the 'Audio' media key to cycleAudioTracks() by default.
Emits: the player core’s 'audioTrack' event with the newly selected track index. (The 'audioTracks' list event fires only when the backend parses the manifest, not when you cycle.)
Checking available tracks
Read the track list before calling cycle methods if you need to check how many tracks are available:
const subtitles = player.subtitles(); // SubtitleTrackRef[]
const audioTracks = player.audioTracks(); // AudioTrackRef[]
if (subtitles.length > 0) {
player.cycleSubtitles();
}
Note: the audio track list may not be populated until after the 'audioTracks' event fires following HLS manifest parse.
Example: subtitle cycle button
import nmplayer from '@nomercy-entertainment/nomercy-video-player';
import { SubtitleOverlayPlugin } from '@nomercy-entertainment/nomercy-video-player/plugins';
const player = nmplayer('player')
.addPlugin(SubtitleOverlayPlugin)
.setup({
baseUrl: 'https://raw.githubusercontent.com/NoMercy-Entertainment/nomercy-media/master/Films',
playlist: [
{
title: 'Sintel',
url: '/Sintel.(2010)/Sintel.(2010).NoMercy.m3u8',
subtitles: [
{
id: 1,
kind: 'subtitles',
label: 'English',
language: 'en',
url: '/Sintel.(2010)/subtitles/Sintel.(2010).NoMercy.eng.full.vtt',
},
],
},
],
});
document.getElementById('sub-btn')?.addEventListener('click', () => {
player.cycleSubtitles();
});