Skip to content

Commit

Permalink
[Fix] Fixed audio selection bug and resolution selection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavPS committed Jun 22, 2021
1 parent 024bee0 commit 5e8ff17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 6 additions & 6 deletions MovieServer/movieserver/pages/api/video/[id]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ALLOWED_QUALITIES = [
'480P',
'360P',
'240P',
'directplay'
'DIRECTPLAY'
];

const WEB_SUPPORTED_AUDIO_CODECS = [
Expand Down Expand Up @@ -113,7 +113,7 @@ export default async (req, res) => {
function getMovieCodecs(movieID) {
return new Promise((resolve, reject) => {
// Assumes no duplicates of languages in the codec
db.many("SELECT language, codec FROM movie_language WHERE movie_id = $1 ORDER BY stream_index", [movieID]).then(result => {
db.many("SELECT language, codec, stream_index FROM movie_language WHERE movie_id = $1 ORDER BY stream_index", [movieID]).then(result => {
resolve(result);
}).catch(error => {
console.log(error);
Expand All @@ -125,7 +125,7 @@ function getMovieCodecs(movieID) {
function getEpisodeCodecs(episodeID) {
return new Promise((resolve, reject) => {
// Assumes no duplicates of languages in the codec
db.many("SELECT language, codec FROM serie_episode_language WHERE serie_episode_id = $1 ORDER BY stream_index", [episodeID]).then(result => {
db.many("SELECT language, codec, stream_index FROM serie_episode_language WHERE serie_episode_id = $1 ORDER BY stream_index", [episodeID]).then(result => {
resolve(result);
}).catch(error => {
console.log(error);
Expand Down Expand Up @@ -200,7 +200,7 @@ function startFFMPEG(filename, offset, language, audioCodecs, req, res) {
Direct play: https://stackoverflow.com/questions/40077681/ffmpeg-converting-from-mkv-to-mp4-without-re-encoding
*/

let quality = req.query.quality;
let quality = req.query.quality.toUpperCase();
if (!ALLOWED_QUALITIES.includes(quality)) {
console.log(`${quality} is not a valid quality selector`);
res.status(404).end();
Expand All @@ -220,9 +220,9 @@ function startFFMPEG(filename, offset, language, audioCodecs, req, res) {
audioSettings.push(`-map 0:${language}?`);

// Default audioTranscoding if for some reason we don't find the language in the array (which shouldn't be possible)
audioSupported = true;
audioSupported = false;
for (let stream of audioCodecs) {
if (stream.language === language) {
if (stream.stream_index === language) {
audioSupported = !audioTranscodingNeeded(stream.codec, WEB_CLIENT);
}
}
Expand Down
8 changes: 7 additions & 1 deletion components/videoComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,13 @@ export default class VideoComponent extends React.Component {

changeResolution(resolution) {
validateServerAccess(this.server, (serverToken) => {
this.source.setAttribute('src', `${this.server.server_ip}/api/video/${this.internalID}?type=${this.type}&token=${serverToken}&start=${this.video.getRealWatchtime()}&quality=${resolution}`);
let audioSource = "";
let activeStream = this.state.audioStreams.activeStream;
if (activeStream != undefined) {
audioSource = `&audio=${activeStream.stream_index}`;
}

this.source.setAttribute('src', `${this.server.server_ip}/api/video/${this.internalID}?type=${this.type}&token=${serverToken}&start=${this.video.getRealWatchtime()}&quality=${resolution}${audioSource}`);
// Change the watchTimeOffset to proberly sync subtitles and seekbar.
this.video.watchTimeOffset = this.video.getRealWatchtime();
this.changeSubtitle(this.state.subtitles.activeSubtitle);
Expand Down

0 comments on commit 5e8ff17

Please sign in to comment.