mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-05-27 08:32:32 +00:00
feat(web): add supportedFeatures and __DEV__ warnings for unsupported methods
This commit is contained in:
@@ -19,6 +19,16 @@ import { VideoPlayerEvents } from "./VideoPlayerEvents";
|
||||
import type { AudioTrack } from "./types/AudioTrack";
|
||||
import type { VideoTrack } from "./types/VideoTrack";
|
||||
import type { QualityLevel } from "./types/QualityLevel";
|
||||
import type { SupportedFeatures } from "./types/SupportedFeatures";
|
||||
|
||||
function warnUnsupported(method: string, feature: keyof SupportedFeatures) {
|
||||
if (__DEV__) {
|
||||
console.warn(
|
||||
`[react-native-video] ${method}() is not yet implemented on native platforms. ` +
|
||||
`Check player.supportedFeatures.${feature} before calling.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
|
||||
private _player: VideoPlayerImpl | undefined;
|
||||
@@ -334,34 +344,40 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
|
||||
return this.player.selectedTrack;
|
||||
}
|
||||
|
||||
// TODO: implement this
|
||||
getAvailableAudioTracks(): AudioTrack[] {
|
||||
warnUnsupported("getAvailableAudioTracks", "audioTrackSelection");
|
||||
return [];
|
||||
}
|
||||
|
||||
selectAudioTrack(_: AudioTrack | null): void {}
|
||||
selectAudioTrack(_: AudioTrack | null): void {
|
||||
warnUnsupported("selectAudioTrack", "audioTrackSelection");
|
||||
}
|
||||
|
||||
get selectedAudioTrack(): AudioTrack | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getAvailableVideoTracks(): VideoTrack[] {
|
||||
warnUnsupported("getAvailableVideoTracks", "videoTrackSelection");
|
||||
return [];
|
||||
}
|
||||
|
||||
selectVideoTrack(_: VideoTrack | null): void {}
|
||||
selectVideoTrack(_: VideoTrack | null): void {
|
||||
warnUnsupported("selectVideoTrack", "videoTrackSelection");
|
||||
}
|
||||
|
||||
get selectedVideoTrack(): VideoTrack | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// quality
|
||||
|
||||
getAvailableQualities(): QualityLevel[] {
|
||||
warnUnsupported("getAvailableQualities", "qualitySelection");
|
||||
return [];
|
||||
}
|
||||
|
||||
selectQuality(_: QualityLevel | null): void {}
|
||||
selectQuality(_: QualityLevel | null): void {
|
||||
warnUnsupported("selectQuality", "qualitySelection");
|
||||
}
|
||||
|
||||
get currentQuality(): QualityLevel | undefined {
|
||||
return undefined;
|
||||
@@ -370,6 +386,14 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
|
||||
get autoQualityEnabled(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
get supportedFeatures(): SupportedFeatures {
|
||||
return {
|
||||
audioTrackSelection: false,
|
||||
videoTrackSelection: false,
|
||||
qualitySelection: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { VideoPlayer };
|
||||
|
||||
@@ -17,6 +17,7 @@ import { MediaSessionHandler } from "./web/MediaSession";
|
||||
import { WebEventEmitter } from "./web/WebEventEmitter";
|
||||
import type { VideoTrack } from "./types/VideoTrack";
|
||||
import type { QualityLevel } from "./types/QualityLevel";
|
||||
import type { SupportedFeatures } from "./types/SupportedFeatures";
|
||||
import {
|
||||
mapVideoJsTracks,
|
||||
type VideoJsPlayer,
|
||||
@@ -397,6 +398,14 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
get supportedFeatures(): SupportedFeatures {
|
||||
return {
|
||||
audioTrackSelection: true,
|
||||
videoTrackSelection: true,
|
||||
qualitySelection: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { VideoPlayer };
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Describes which optional features are supported by the current player platform.
|
||||
* Use this to check feature availability before calling platform-specific methods.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* if (player.supportedFeatures.audioTrackSelection) {
|
||||
* const tracks = player.getAvailableAudioTracks();
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export interface SupportedFeatures {
|
||||
/** Whether audio track listing and selection is supported. @platform web */
|
||||
audioTrackSelection: boolean;
|
||||
/** Whether video track listing and selection is supported. @platform web */
|
||||
videoTrackSelection: boolean;
|
||||
/** Whether quality level listing and selection is supported. @platform web */
|
||||
qualitySelection: boolean;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { IgnoreSilentSwitchMode } from './IgnoreSilentSwitchMode';
|
||||
import type { MixAudioMode } from './MixAudioMode';
|
||||
import type { SupportedFeatures } from './SupportedFeatures';
|
||||
import type { TextTrack } from './TextTrack';
|
||||
import type { VideoPlayerSourceBase } from './VideoPlayerSourceBase';
|
||||
import type { VideoPlayerStatus } from './VideoPlayerStatus';
|
||||
@@ -171,4 +172,17 @@ export interface VideoPlayerBase {
|
||||
* @returns The currently selected text track, or undefined if none is selected
|
||||
*/
|
||||
readonly selectedTrack?: TextTrack;
|
||||
|
||||
/**
|
||||
* Describes which optional features are supported on the current platform.
|
||||
* Use this to check availability before calling platform-specific methods.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* if (player.supportedFeatures.qualitySelection) {
|
||||
* const qualities = player.getAvailableQualities();
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
readonly supportedFeatures: SupportedFeatures;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export type { TextTrack } from "./core/types/TextTrack";
|
||||
export type { AudioTrack } from "./core/types/AudioTrack";
|
||||
export type { VideoTrack } from "./core/types/VideoTrack";
|
||||
export type { QualityLevel } from "./core/types/QualityLevel";
|
||||
export type { SupportedFeatures } from "./core/types/SupportedFeatures";
|
||||
export type { VideoConfig, VideoSource } from "./core/types/VideoConfig";
|
||||
export type {
|
||||
LibraryError,
|
||||
|
||||
Reference in New Issue
Block a user