-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/player default audio track #317
Changes from 3 commits
ba1776b
a198fe6
efa9e20
4a482c5
c2b2447
daf39c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const React = require('react'); | |
const PropTypes = require('prop-types'); | ||
const classnames = require('classnames'); | ||
const debounce = require('lodash.debounce'); | ||
const langs = require('langs'); | ||
const { useRouteFocused } = require('stremio-router'); | ||
const { useServices } = require('stremio/services'); | ||
const { HorizontalNavBar, Button, useFullscreen, useBinaryState, useToast, useStreamingServer, withCoreSuspender } = require('stremio/common'); | ||
|
@@ -40,6 +41,7 @@ const Player = ({ urlParams, queryParams }) => { | |
const [subtitlesMenuOpen, , closeSubtitlesMenu, toggleSubtitlesMenu] = useBinaryState(false); | ||
const [infoMenuOpen, , closeInfoMenu, toggleInfoMenu] = useBinaryState(false); | ||
const [videosMenuOpen, , closeVideosMenu, toggleVideosMenu] = useBinaryState(false); | ||
const defaultAudioTrackSelected = React.useRef(false); | ||
const [error, setError] = React.useState(null); | ||
const [videoState, setVideoState] = React.useReducer( | ||
(videoState, nextVideoState) => ({ ...videoState, ...nextVideoState }), | ||
|
@@ -313,6 +315,17 @@ const Player = ({ urlParams, queryParams }) => { | |
pausedChanged(videoState.paused); | ||
} | ||
}, [videoState.paused]); | ||
React.useEffect(() => { | ||
if (defaultAudioTrackSelected.current === false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const findTrackByLang = (tracks, lang) => tracks.find((track) => track.lang === lang || langs.where('1', track.lang)?.[2] === lang); | ||
const audioTrack = findTrackByLang(videoState.audioTracks, settings.audioLanguage); | ||
|
||
if (audioTrack && audioTrack.id) { | ||
onAudioTrackSelected(audioTrack.id); | ||
defaultAudioTrackSelected.current = true; | ||
} | ||
} | ||
}, [videoState.audioTracks, settings.audioLanguage]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we trigger this effect when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe that's not necessary yes |
||
React.useEffect(() => { | ||
if ((!Array.isArray(videoState.subtitlesTracks) || videoState.subtitlesTracks.length === 0) && | ||
(!Array.isArray(videoState.extraSubtitlesTracks) || videoState.extraSubtitlesTracks.length === 0) && | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reset defaultAudioTrackSelected to false when videoState.stream changes