import TinyDebugger from '../tools/TinyDebugger.mjs'; import { BaseMediaAdapter } from '../media/TinyMediaPlayer/index.mjs'; export type PictureDataType = import('../../basics/mediaContent.mjs').PictureDataType; export type MediaContent = import('../../basics/mediaContent.mjs').MediaContent; export type MediaContentBase = import('../../basics/mediaContent.mjs').MediaContentBase; export type MediaContentMetadata = import('../../basics/mediaContent.mjs').MediaContentMetadata; export type ParseMediaContentMetadata = import('../../basics/mediaContent.mjs').ParseMediaContentMetadata; export type LoadingMediaProgress = import('../../basics/mediaContent.mjs').LoadingMediaProgress; export type MediaLoadingErrorData = import('../../basics/mediaContent.mjs').MediaLoadingErrorData; export type UnknownArtistGetter = import('../../basics/mediaContent.mjs').UnknownArtistGetter; export type ContentTimeData = import('./TinyMediaPlayer/index.mjs').ContentTimeData; export type ContentData = import('./TinyMediaPlayer/index.mjs').ContentData; export type LoopModeType = 'NONE' | 'TRACK' | 'PLAYLIST'; export type TinyMediaPlayerOptions = { /** * - Whether to automatically save the volume in localStorage. */ persistVolume?: boolean; /** * - The specific key name used for localStorage cache. */ volumeStorageKey?: string; /** * - If true, clicking 'previous' repeats the current track on the first click. */ repeatCurrentOnPrev?: boolean; /** * - If true, volume fades smoothly during play/pause transitions. */ smoothPlayPauseVolume?: boolean; /** * - If true, volume fades smoothly to zero when stopping. */ smoothStopVolume?: boolean; /** * - Whether to enable internal debug logging. */ debugMode?: boolean; /** * - Whether to enable log color support. */ useLogColors?: boolean; /** * - A custom logger object (must implement console methods). */ logger?: Partial; }; export type SearchResult = { /** * - The matched media content. */ track: MediaContent; /** * - The current index of the track in the playlist. */ index: number; }; /** * @typedef {import('../../basics/mediaContent.mjs').PictureDataType} PictureDataType * @typedef {import('../../basics/mediaContent.mjs').MediaContent} MediaContent * @typedef {import('../../basics/mediaContent.mjs').MediaContentBase} MediaContentBase * @typedef {import('../../basics/mediaContent.mjs').MediaContentMetadata} MediaContentMetadata * @typedef {import('../../basics/mediaContent.mjs').ParseMediaContentMetadata} ParseMediaContentMetadata * @typedef {import('../../basics/mediaContent.mjs').LoadingMediaProgress} LoadingMediaProgress * @typedef {import('../../basics/mediaContent.mjs').MediaLoadingErrorData} MediaLoadingErrorData * @typedef {import('../../basics/mediaContent.mjs').UnknownArtistGetter} UnknownArtistGetter * @typedef {import('./TinyMediaPlayer/index.mjs').ContentTimeData} ContentTimeData * @typedef {import('./TinyMediaPlayer/index.mjs').ContentData} ContentData */ /** * The loop configuration modes. * @typedef {'NONE' | 'TRACK' | 'PLAYLIST'} LoopModeType */ /** * Configuration options for initializing the TinyMediaPlayer. * @typedef {Object} TinyMediaPlayerOptions * @property {boolean} [persistVolume=false] - Whether to automatically save the volume in localStorage. * @property {string} [volumeStorageKey='tiny_media_player_volume'] - The specific key name used for localStorage cache. * @property {boolean} [repeatCurrentOnPrev=false] - If true, clicking 'previous' repeats the current track on the first click. * @property {boolean} [smoothPlayPauseVolume=false] - If true, volume fades smoothly during play/pause transitions. * @property {boolean} [smoothStopVolume=false] - If true, volume fades smoothly to zero when stopping. * @property {boolean} [debugMode=false] - Whether to enable internal debug logging. * @property {boolean} [useLogColors=false] - Whether to enable log color support. * @property {Partial} [logger=console] - A custom logger object (must implement console methods). */ /** * Represents a search match containing the media object and its exact playlist index. * @typedef {Object} SearchResult * @property {MediaContent} track - The matched media content. * @property {number} index - The current index of the track in the playlist. */ /** * A universal media player manager capable of orchestrating multiple API adapters. */ declare class TinyMediaPlayer extends TinyDebugger { #private; static BaseMediaAdapter: typeof BaseMediaAdapter; /** * Gets the current value used to represent unknown artists. * @returns {UnknownArtistGetter} */ static get unknownArtist(): UnknownArtistGetter; /** * Sets the value used to represent unknown artists. * @param {UnknownArtistGetter} value - A string or a function that returns a string. * @throws {TypeError} If the value is neither a string nor a function. */ static set unknownArtist(value: UnknownArtistGetter); /** * A Static Factory Method that prepares a MediaContent object by * extracting metadata from an audio source. * * @param {string | HTMLMediaElement} source - A URL string or an existing Audio object. * @param {Partial & { id?: string; weight?: number }} [defaultMetadata={}] - Optional default metadata that overrides automatic extraction. * @param {Partial & { id?: string; weight?: number }} [metadata={}] - Optional manual metadata that overrides automatic extraction. * @param {ParseMediaContentMetadata} [parseFile] - Private helper to interface with parseFile. * @param {Object} [callbacks={}] - Callbacks for monitoring the loading process. * @param {(progress: LoadingMediaProgress) => void} [callbacks.onProgress] - Callback triggered on stage changes. * @param {(error: MediaLoadingErrorData) => void} [callbacks.onError] - Callback triggered when a non-fatal or fatal error occurs. * @param {boolean} [convertBase64toBlob=true] - If the image content needs to be converted directly into a high-performance Blob URL, use this method. * @returns {Promise} A promise that resolves to a valid MediaContent object. * @throws {MediaLoadingError} If the preparation process fails at any stage. */ static parseContent(source: string | HTMLMediaElement, defaultMetadata?: Partial & { id?: string; weight?: number; }, metadata?: Partial & { id?: string; weight?: number; }, parseFile?: ParseMediaContentMetadata, callbacks?: { onProgress?: (progress: LoadingMediaProgress) => void; onError?: (error: MediaLoadingErrorData) => void; }, convertBase64toBlob?: boolean): Promise; get destroyed(): boolean; /** @returns {number} The duration (ms) of the volume fade speed. */ get fadeVolumeSpeed(): number; /** * @param {number} value - The new duration in milliseconds. * @throws {TypeError} If the value is not a number. * @throws {RangeError} If the value is negative. */ set fadeVolumeSpeed(value: number); /** @returns {number} The duration (ms) before the prev click state resets. */ get prevClickTimeoutDuration(): number; /** * @param {number} value - The new duration in milliseconds. * @throws {TypeError} If the value is not a number. * @throws {RangeError} If the value is negative. */ set prevClickTimeoutDuration(value: number); /** @returns {boolean} True if clicking 'previous' repeats the current track on the first click. */ get repeatCurrentOnPrev(): boolean; /** * @param {boolean} value - The repeat mode state. * @throws {TypeError} If the value is not a boolean. */ set repeatCurrentOnPrev(value: boolean); /** @returns {boolean} True if volume fades smoothly during play/pause transitions. */ get smoothPlayPauseVolume(): boolean; /** * @param {boolean} value - The smooth play/pause volume mode. * @throws {TypeError} If the value is not a boolean. */ set smoothPlayPauseVolume(value: boolean); /** @returns {boolean} True if volume fades smoothly to zero when stopping. */ get smoothStopVolume(): boolean; /** * @param {boolean} value - The smooth stop volume mode. * @throws {TypeError} If the value is not a boolean. */ set smoothStopVolume(value: boolean); /** * @param {TinyMediaPlayerOptions} [options={}] - Configuration parameters for the player. * @throws {TypeError} If options is not a valid object. * @throws {TypeError} If option values do not match their expected types. * @throws {RangeError} If numeric options are out of valid ranges. */ constructor(options?: TinyMediaPlayerOptions); /** * Calculates a random index based on the weighted probability of each track, * strictly excluding the currently active track to prevent immediate repetition. * @returns {number} The selected index. * @private */ private _getWeightedRandomIndex; /** @returns {MediaContent[]} A shallow copy of the current playlist. */ get playlist(): MediaContent[]; /** * @param {MediaContent[]} value - The new playlist array. * @throws {TypeError} If the value is not an array. */ set playlist(value: MediaContent[]); /** @returns {number} The current active index in the playlist. */ get currentIndex(): number; /** * @param {number} value - The index to set as current. * @throws {TypeError} If the value is not a number. * @throws {RangeError} If the index is out of the playlist bounds (unless -1 for empty). */ set currentIndex(value: number); /** @returns {LoopModeType} The current loop configuration. */ get loopMode(): LoopModeType; /** * @param {LoopModeType} value - The desired loop mode. * @throws {TypeError} If the value is not a valid LoopModeType. */ set loopMode(value: LoopModeType); /** @returns {boolean} The current random mode status. */ get isRandom(): boolean; /** * @param {boolean} value - True to enable random playback, false otherwise. * @throws {TypeError} If the value is not a boolean. */ set isRandom(value: boolean); /** @returns {boolean} True if media is actively playing. */ get isPlaying(): boolean; /** @returns {number} The current volume level (0.0 to 1.0). */ get volume(): number; /** * @param {number} value - The volume level to set. * @throws {TypeError} If the value is not a number. * @throws {RangeError} If the value is outside the 0.0 to 1.0 range. */ set volume(value: number); /** @returns {boolean} Whether the volume cache is currently enabled. */ get persistVolume(): boolean; /** * @param {boolean} value - True to save volume dynamically to localStorage. * @throws {TypeError} If the value is not a boolean. */ set persistVolume(value: boolean); /** @returns {string} The localStorage key used for volume caching. */ get volumeStorageKey(): string; /** * @param {string} value - The custom storage key string. * @throws {TypeError} If the value is not a string or is empty. */ set volumeStorageKey(value: string); /** @returns {boolean} True if the player is currently muted. */ get isMuted(): boolean; /** * Mutes the current playback. * @returns {Promise} */ mute(): Promise; /** * Unmutes the current playback. * @returns {Promise} */ unMute(): Promise; get adapters(): BaseMediaAdapter[]; get adaptersSize(): number; static get defaultAdapterEventNames(): string[]; /** @param {string[]} value */ static set defaultAdapterEventNames(value: string[]); /** * Registers a new media API adapter. * @param {BaseMediaAdapter} adapter - An instance extending BaseMediaAdapter. * @throws {TypeError} If the adapter is invalid. */ registerAdapter(adapter: BaseMediaAdapter): void; /** * Removes a media API adapter. * @param {BaseMediaAdapter} adapter - An instance extending BaseMediaAdapter. * @throws {TypeError} If adapter is invalid. */ removeAdapter(adapter: BaseMediaAdapter): boolean; /** * Destroys and removes a media API adapter. * @param {BaseMediaAdapter} adapter - An instance extending BaseMediaAdapter. * @throws {TypeError} If adapter is invalid. */ destroyAdapter(adapter: BaseMediaAdapter): boolean; /** * If exists a media API adapter. * @param {BaseMediaAdapter} adapter - An instance extending BaseMediaAdapter. * @throws {TypeError} If adapter is invalid. */ hasAdapter(adapter: BaseMediaAdapter): boolean; /** * Destroys and removes all registered media adapters. */ destroyAllAdapters(): void; /** * Clears all registered media adapters. */ clearAdapters(): void; /** * Helper to find the correct API wrapper for the content. * @param {MediaContent} content - The content to check. * @returns {BaseMediaAdapter | null} The compatible adapter, or null if empty. * @throws {TypeError} If the content is invalid. */ getMediaAdapter(content: MediaContent): BaseMediaAdapter | null; /** * Adds a new event to be listened to on the adapters. * @param {string} eventName - The name of the event to add. * @throws {TypeError} If the event name is not a string. */ addAdapterEvent(eventName: string): void; /** * Removes an event from the list of listened events. * @param {string} eventName - The name of the event to remove. * @throws {TypeError} If the event name is not a string. */ removeAdapterEvent(eventName: string): void; /** * Resets the event list to the factory default state: ['timeupdate', 'ended']. * @throws {TypeError} If the event name is not a string. */ resetAdapterEvents(): void; /** * Adds a new item to the end of the playlist. * @param {MediaContent} content - The structured media content object. * @returns {number} The new length of the playlist. * @throws {TypeError} If content is invalid or missing required base properties. */ addTrack(content: MediaContent): number; /** * Checks if a track exists at the specified index. * @param {number} index - The target index. * @returns {boolean} True if the track exists at the specified index. * @throws {TypeError} If the index is not a number. */ existsTrack(index: number): boolean; /** * Retrieves the track at the specified index. * @param {number} index - The target index. * @returns {MediaContent} The media content object. * @throws {TypeError} If the index is not a number. * @throws {RangeError} If the index is out of the playlist bounds. */ getTrack(index: number): MediaContent; /** * Removes the track at the specified index and manages playback state accordingly. * @param {number} index - The index of the track to remove. * @returns {Promise} * @throws {TypeError} If the index is not a number. * @throws {RangeError} If the index is out of bounds. */ removeTrack(index: number): Promise; /** * Searches the playlist for tracks matching a string query or a custom evaluation function. * @param {string | ((content: MediaContent) => boolean)} query - The search string (checked against title, artist, album) or a callback returning a boolean. * @returns {SearchResult[]} An array containing the matched tracks and their corresponding indices. * @throws {TypeError} If the query is neither a string nor a function. */ searchTrack(query: string | ((content: MediaContent) => boolean)): SearchResult[]; /** * Clears the entire playlist and stops playback. */ clearPlaylist(): Promise; /** * Starts or resumes playback of the current track. * @returns {Promise} */ play(): Promise; /** * Pauses the current track. * @returns {Promise} */ pause(): Promise; /** * Stops playback completely. * @returns {Promise} */ stop(): Promise; /** * Advances to the next track based on random and loop modes. * @returns {Promise} */ next(): Promise; /** * Returns to the previous track. * @returns {Promise} */ prev(): Promise; /** * Jumps directly to a specific index in the playlist. * @param {number} index - The target index to skip to. * @returns {Promise} * @throws {TypeError} If the index is not a number. * @throws {RangeError} If the index is out of the playlist bounds. */ skipTo(index: number): Promise; /** * Jumps to a specific absolute time in the timeline. * @param {number} timeMs - The target time in milliseconds. * @returns {Promise} * @throws {TypeError} If timeMs is not a number. * @throws {RangeError} If timeMs is negative. */ seek(timeMs: number): Promise; /** * Moves the timeline forwards or backwards by a specified step amount. * @param {number} stepMs - The amount of milliseconds to step (positive for forward, negative for backward). * @throws {TypeError} If stepMs is not a number. * @returns {Promise} */ step(stepMs: number): Promise; /** * Gets the current playback time. * @returns {number} The current time in milliseconds. */ getCurrentTime(): number; /** * Gets the total duration of the current track. * @returns {number} The total duration in milliseconds. */ getTotalDuration(): number; /** * Gets the remaining time until the current track ends. * @returns {number} The remaining time in milliseconds. */ getRemainingTime(): number; /** * Gets the percentage of the current track that has been played. * @returns {number} A value between 0 and 100. */ getPlaybackPercentage(): number; /** * Checks whether the media adapter is paused. * @returns {boolean} True if the adapter is ready, false otherwise. */ get isPaused(): boolean; /** * Checks whether the media adapter is ended. * @returns {boolean} True if the adapter is ready, false otherwise. */ get isEnded(): boolean; /** * Retrieves the metadata of the currently loaded content, returning a structured * object containing details such as the content ID, title, author, and duration. * @returns {Promise} */ getContentData(): Promise; /** * Asynchronously waits until the content media adapter is fully initialized and ready. * @returns {Promise} A promise that resolves once the adapter is ready. */ waitIsReady(): Promise; /** * Safely destroys the TinyMediaPlayer instance. * This method stops active playback, clears the internal playlist, * removes all registered media adapters, and detaches all event listeners * to ensure proper garbage collection and prevent memory leaks. * * @returns {Promise} A promise that resolves when the destruction sequence is complete. */ destroy(): Promise; } export default TinyMediaPlayer; //# sourceMappingURL=TinyMediaPlayer.d.mts.map