mirror of
https://github.com/FreeTubeApp/FreeTube
synced 2024-11-22 09:56:23 +01:00
Merge 6c398cac99
into dc65eece29
This commit is contained in:
commit
4e4407dacd
@ -1252,24 +1252,21 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {'dash'|'audio'|null} previousFormat
|
|
||||||
* @param {number|null} playbackPosition
|
* @param {number|null} playbackPosition
|
||||||
|
* @param {number|undefined} previousQuality
|
||||||
*/
|
*/
|
||||||
async function setLegacyQuality(previousFormat = null, playbackPosition = null) {
|
async function setLegacyQuality(playbackPosition = null, previousQuality = undefined) {
|
||||||
|
if (typeof previousQuality === 'undefined') {
|
||||||
|
if (defaultQuality.value === 'auto') {
|
||||||
|
previousQuality = Infinity
|
||||||
|
} else {
|
||||||
|
previousQuality = defaultQuality.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @type {object[]} */
|
/** @type {object[]} */
|
||||||
const legacyFormats = props.legacyFormats
|
const legacyFormats = props.legacyFormats
|
||||||
|
|
||||||
let previousQuality
|
|
||||||
if (previousFormat === 'dash') {
|
|
||||||
const previousTrack = player.getVariantTracks().find(track => track.active)
|
|
||||||
|
|
||||||
previousQuality = previousTrack.height > previousTrack.width ? previousTrack.width : previousTrack.height
|
|
||||||
} else if (defaultQuality.value === 'auto') {
|
|
||||||
previousQuality = Infinity
|
|
||||||
} else {
|
|
||||||
previousQuality = defaultQuality.value
|
|
||||||
}
|
|
||||||
|
|
||||||
const isPortrait = legacyFormats[0].height > legacyFormats[0].width
|
const isPortrait = legacyFormats[0].height > legacyFormats[0].width
|
||||||
|
|
||||||
let matches = legacyFormats.filter(variant => {
|
let matches = legacyFormats.filter(variant => {
|
||||||
@ -2147,17 +2144,28 @@ export default defineComponent({
|
|||||||
|
|
||||||
// #endregion keyboard shortcuts
|
// #endregion keyboard shortcuts
|
||||||
|
|
||||||
|
let ignoreErrors = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {shaka.util.Error} error
|
* @param {shaka.util.Error} error
|
||||||
* @param {string} context
|
* @param {string} context
|
||||||
* @param {object?} details
|
* @param {object?} details
|
||||||
*/
|
*/
|
||||||
function handleError(error, context, details) {
|
function handleError(error, context, details) {
|
||||||
|
// These two errors are just wrappers around another error, so use the original error instead
|
||||||
|
// As they can be nested (e.g. multiple googlevideo redirects because the Invidious server was far away from the user) we should pick the inner most one
|
||||||
|
while (error.code === shaka.util.Error.Code.REQUEST_FILTER_ERROR || error.code === shaka.util.Error.Code.RESPONSE_FILTER_ERROR) {
|
||||||
|
error = error.data[0]
|
||||||
|
}
|
||||||
|
|
||||||
logShakaError(error, context, props.videoId, details)
|
logShakaError(error, context, props.videoId, details)
|
||||||
|
|
||||||
// text related errors aren't serious (captions and seek bar thumbnails), so we should just log them
|
// text related errors aren't serious (captions and seek bar thumbnails), so we should just log them
|
||||||
// TODO: consider only emitting when the severity is crititcal?
|
// TODO: consider only emitting when the severity is crititcal?
|
||||||
if (error.category !== shaka.util.Error.Category.TEXT) {
|
if (!ignoreErrors && error.category !== shaka.util.Error.Category.TEXT) {
|
||||||
|
// don't react to multiple consecutive errors, otherwise we don't give the format fallback from the previous error a chance to work
|
||||||
|
ignoreErrors = true
|
||||||
|
|
||||||
emit('error', error)
|
emit('error', error)
|
||||||
|
|
||||||
stopPowerSaveBlocker()
|
stopPowerSaveBlocker()
|
||||||
@ -2414,7 +2422,7 @@ export default defineComponent({
|
|||||||
handleError(error, 'loading dash/audio manifest and setting default quality in mounted')
|
handleError(error, 'loading dash/audio manifest and setting default quality in mounted')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await setLegacyQuality(null, props.startTime)
|
await setLegacyQuality(props.startTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2532,9 +2540,17 @@ export default defineComponent({
|
|||||||
* @param {'dash'|'audio'|'legacy'} oldFormat
|
* @param {'dash'|'audio'|'legacy'} oldFormat
|
||||||
*/
|
*/
|
||||||
async (newFormat, oldFormat) => {
|
async (newFormat, oldFormat) => {
|
||||||
|
ignoreErrors = true
|
||||||
|
|
||||||
// format switch happened before the player loaded, probably because of an error
|
// format switch happened before the player loaded, probably because of an error
|
||||||
// as there are no previous player settings to restore, we should treat it like this was the original format
|
// as there are no previous player settings to restore, we should treat it like this was the original format
|
||||||
if (!hasLoaded.value) {
|
if (!hasLoaded.value) {
|
||||||
|
try {
|
||||||
|
await player.unload()
|
||||||
|
} catch { }
|
||||||
|
|
||||||
|
ignoreErrors = false
|
||||||
|
|
||||||
player.configure(getPlayerConfig(newFormat, defaultQuality.value === 'auto'))
|
player.configure(getPlayerConfig(newFormat, defaultQuality.value === 'auto'))
|
||||||
|
|
||||||
await performFirstLoad()
|
await performFirstLoad()
|
||||||
@ -2597,6 +2613,12 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await player.unload()
|
||||||
|
} catch { }
|
||||||
|
|
||||||
|
ignoreErrors = false
|
||||||
|
|
||||||
player.configure(getPlayerConfig(newFormat, useAutoQuality))
|
player.configure(getPlayerConfig(newFormat, useAutoQuality))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -2634,7 +2656,21 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
activeLegacyFormat.value = null
|
activeLegacyFormat.value = null
|
||||||
} else {
|
} else {
|
||||||
await setLegacyQuality(oldFormat, playbackPosition)
|
let previousQuality
|
||||||
|
|
||||||
|
if (oldFormat === 'dash') {
|
||||||
|
const previousTrack = player.getVariantTracks().find(track => track.active)
|
||||||
|
|
||||||
|
previousQuality = previousTrack.height > previousTrack.width ? previousTrack.width : previousTrack.height
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await player.unload()
|
||||||
|
} catch { }
|
||||||
|
|
||||||
|
ignoreErrors = false
|
||||||
|
|
||||||
|
await setLegacyQuality(playbackPosition, previousQuality)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasPaused) {
|
if (wasPaused) {
|
||||||
@ -2702,6 +2738,8 @@ export default defineComponent({
|
|||||||
* To workaround that we destroy the player first and wait for it to finish before we unmount this component.
|
* To workaround that we destroy the player first and wait for it to finish before we unmount this component.
|
||||||
*/
|
*/
|
||||||
async function destroyPlayer() {
|
async function destroyPlayer() {
|
||||||
|
ignoreErrors = true
|
||||||
|
|
||||||
if (ui) {
|
if (ui) {
|
||||||
// destroying the ui also destroys the player
|
// destroying the ui also destroys the player
|
||||||
await ui.destroy()
|
await ui.destroy()
|
||||||
|
Loading…
Reference in New Issue
Block a user