mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 04:50:12 +02:00
shamelessly copy transcoding config from NavidromeUI
This commit is contained in:
@@ -37,6 +37,52 @@ import { toast } from '/@/shared/components/toast/toast';
|
||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||
import { PlayerType } from '/@/shared/types/types';
|
||||
|
||||
const CODEC_PROBES = [
|
||||
{ codec: 'mp3', container: 'mp3', mime: 'audio/mpeg' },
|
||||
{ codec: 'aac', container: 'mp4', mime: 'audio/mp4; codecs="mp4a.40.2"' },
|
||||
{ codec: 'opus', container: 'ogg', mime: 'audio/ogg; codecs="opus"' },
|
||||
{ codec: 'vorbis', container: 'ogg', mime: 'audio/ogg; codecs="vorbis"' },
|
||||
{ codec: 'flac', container: 'flac', mime: 'audio/flac' },
|
||||
{ codec: 'wav', container: 'wav', mime: 'audio/wav' },
|
||||
{ codec: 'alac', container: 'mp4', mime: 'audio/mp4; codecs="alac"' },
|
||||
];
|
||||
|
||||
const DEFAULT_TRANSCODING_PROFILES = [
|
||||
{ audioCodec: 'opus', container: 'ogg', protocol: 'http' },
|
||||
{ audioCodec: 'mp3', container: 'mp3', protocol: 'http' },
|
||||
];
|
||||
|
||||
const DIRECT_PLAY_PROFILES: {
|
||||
audioCodecs: string[];
|
||||
containers: string[];
|
||||
protocols: string[];
|
||||
}[] = [];
|
||||
|
||||
export function getDefaultTranscodingProfiles() {
|
||||
return DEFAULT_TRANSCODING_PROFILES;
|
||||
}
|
||||
|
||||
export function getDirectPlayProfiles() {
|
||||
return DIRECT_PLAY_PROFILES;
|
||||
}
|
||||
|
||||
// Shamelessly taken from NavidromeUI
|
||||
function detectBrowserProfile() {
|
||||
const audio = new Audio();
|
||||
|
||||
for (const { codec, container, mime } of CODEC_PROBES) {
|
||||
if (audio.canPlayType(mime) === 'probably') {
|
||||
DIRECT_PLAY_PROFILES.push({
|
||||
audioCodecs: [codec],
|
||||
containers: [container],
|
||||
protocols: ['http'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return DIRECT_PLAY_PROFILES;
|
||||
}
|
||||
|
||||
export const AudioPlayers = () => {
|
||||
const playbackType = usePlaybackType();
|
||||
const serverId = useCurrentServerId();
|
||||
@@ -49,6 +95,11 @@ export const AudioPlayers = () => {
|
||||
} = usePlaybackSettings();
|
||||
const { setWebAudio, webAudio: audioContext } = useWebAudio();
|
||||
|
||||
useEffect(() => {
|
||||
console.log('getDirectPlayProfiles');
|
||||
detectBrowserProfile();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SleepTimerHook />
|
||||
|
||||
Reference in New Issue
Block a user