Add better default quality logic
This commit is contained in:
parent
cf61d04f46
commit
4f04eb7640
|
@ -208,6 +208,10 @@ export default Vue.extend({
|
||||||
if (typeof lengthSeconds === 'string') {
|
if (typeof lengthSeconds === 'string') {
|
||||||
return lengthSeconds
|
return lengthSeconds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof lengthSeconds === 'undefined') {
|
||||||
|
return '0:00'
|
||||||
|
}
|
||||||
let durationText = ''
|
let durationText = ''
|
||||||
let time = lengthSeconds
|
let time = lengthSeconds
|
||||||
let hours = 0
|
let hours = 0
|
||||||
|
|
|
@ -50,6 +50,7 @@ export default Vue.extend({
|
||||||
player: null,
|
player: null,
|
||||||
useDash: false,
|
useDash: false,
|
||||||
useHls: false,
|
useHls: false,
|
||||||
|
selectedDefaultQuality: '',
|
||||||
activeSourceList: [],
|
activeSourceList: [],
|
||||||
mouseTimeout: null,
|
mouseTimeout: null,
|
||||||
dataSetup: {
|
dataSetup: {
|
||||||
|
@ -110,80 +111,6 @@ export default Vue.extend({
|
||||||
|
|
||||||
autoplayVideos: function () {
|
autoplayVideos: function () {
|
||||||
return this.$store.getters.getAutoplayVideos
|
return this.$store.getters.getAutoplayVideos
|
||||||
},
|
|
||||||
|
|
||||||
selectedDefaultQuality: function () {
|
|
||||||
let selectedQuality = ''
|
|
||||||
|
|
||||||
if (this.sourceList.length === 0) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof (this.sourceList[0].qualityLabel) === 'number') {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
const maxAvailableQuality = parseInt(this.sourceList[this.sourceList.length - 1].qualityLabel.replace(/p|k/, ''))
|
|
||||||
|
|
||||||
switch (maxAvailableQuality) {
|
|
||||||
case 4:
|
|
||||||
if (this.defaultQuality >= 2160) {
|
|
||||||
return '4k'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 8:
|
|
||||||
if (this.defaultQuality >= 4320) {
|
|
||||||
return '8k'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 144:
|
|
||||||
if (this.defaultQuality >= 144) {
|
|
||||||
return '144p'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 240:
|
|
||||||
if (this.defaultQuality >= 240) {
|
|
||||||
return '240p'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 360:
|
|
||||||
if (this.defaultQuality >= 360) {
|
|
||||||
return '360p'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 480:
|
|
||||||
if (this.defaultQuality >= 480) {
|
|
||||||
return '480p'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 720:
|
|
||||||
if (this.defaultQuality >= 720) {
|
|
||||||
return '720p'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 1080:
|
|
||||||
if (this.defaultQuality >= 1080) {
|
|
||||||
return '1080p'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 1440:
|
|
||||||
if (this.defaultQuality >= 1440) {
|
|
||||||
return '1440p'
|
|
||||||
}
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
return maxAvailableQuality + 'p'
|
|
||||||
}
|
|
||||||
|
|
||||||
this.activeSourceList.forEach((source) => {
|
|
||||||
if (typeof (source.qualityLabel) !== 'undefined') {
|
|
||||||
if (this.determineDefaultQuality(source.qualityLabel)) {
|
|
||||||
selectedQuality = source.qualityLabel
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return selectedQuality
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -215,11 +142,12 @@ export default Vue.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initializePlayer: function () {
|
initializePlayer: async function () {
|
||||||
const videoPlayer = document.getElementById(this.id)
|
const videoPlayer = document.getElementById(this.id)
|
||||||
if (videoPlayer !== null) {
|
if (videoPlayer !== null) {
|
||||||
if (!this.useDash) {
|
if (!this.useDash) {
|
||||||
qualitySelector(videojs, { showQualitySelectionLabelInControlBar: true })
|
qualitySelector(videojs, { showQualitySelectionLabelInControlBar: true })
|
||||||
|
await this.determineDefaultQuality()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.player = videojs(videoPlayer)
|
this.player = videojs(videoPlayer)
|
||||||
|
@ -227,10 +155,12 @@ export default Vue.extend({
|
||||||
this.player.volume(this.volume)
|
this.player.volume(this.volume)
|
||||||
this.player.playbackRate(this.defaultPlayback)
|
this.player.playbackRate(this.defaultPlayback)
|
||||||
|
|
||||||
|
if (this.storyboardSrc !== '') {
|
||||||
this.player.vttThumbnails({
|
this.player.vttThumbnails({
|
||||||
src: this.storyboardSrc,
|
src: this.storyboardSrc,
|
||||||
showTimestamp: true
|
showTimestamp: true
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (this.useDash) {
|
if (this.useDash) {
|
||||||
this.dataSetup.plugins.httpSourceSelector = {
|
this.dataSetup.plugins.httpSourceSelector = {
|
||||||
|
@ -284,26 +214,60 @@ export default Vue.extend({
|
||||||
|
|
||||||
determineDefaultQuality: function (label) {
|
determineDefaultQuality: function (label) {
|
||||||
if (this.useDash) {
|
if (this.useDash) {
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (label.includes('p')) {
|
if (this.sourceList.length === 0) {
|
||||||
const selectedQuality = parseInt(label.replace('p', ''))
|
return ''
|
||||||
return this.defaultQuality === selectedQuality
|
|
||||||
} else if (label.includes('k')) {
|
|
||||||
const hdQuality = parseInt(label.replace('k', ''))
|
|
||||||
|
|
||||||
switch (hdQuality) {
|
|
||||||
case 4:
|
|
||||||
return this.defaultQuality === 2160
|
|
||||||
case 8:
|
|
||||||
return this.defaultQuality === 4320
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
console.log('Invalid label')
|
if (typeof (this.sourceList[0].qualityLabel) === 'number') {
|
||||||
return false
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
let maxAvailableQuality = parseInt(this.sourceList[this.sourceList.length - 1].qualityLabel.replace(/p|k/, ''))
|
||||||
|
|
||||||
|
if (maxAvailableQuality === 4) {
|
||||||
|
maxAvailableQuality = 2160
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxAvailableQuality === 8) {
|
||||||
|
maxAvailableQuality = 4320
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxAvailableQuality < this.defaultQuality) {
|
||||||
|
this.selectedDefaultQuality = this.sourceList[this.sourceList.length - 1].qualityLabel
|
||||||
|
}
|
||||||
|
|
||||||
|
const reversedList = [].concat(this.sourceList).reverse()
|
||||||
|
|
||||||
|
reversedList.forEach((source, index) => {
|
||||||
|
let qualityNumber = parseInt(source.qualityLabel.replace(/p|k/, ''))
|
||||||
|
if (qualityNumber === 4) {
|
||||||
|
qualityNumber = 2160
|
||||||
|
}
|
||||||
|
if (qualityNumber === 8) {
|
||||||
|
qualityNumber = 4320
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < (this.sourceList.length - 1)) {
|
||||||
|
let upperQualityNumber = parseInt(reversedList[index + 1].qualityLabel.replace(/p|k/, ''))
|
||||||
|
if (upperQualityNumber === 4) {
|
||||||
|
upperQualityNumber = 2160
|
||||||
|
}
|
||||||
|
if (upperQualityNumber === 8) {
|
||||||
|
upperQualityNumber = 4320
|
||||||
|
}
|
||||||
|
if (this.defaultQuality >= qualityNumber && this.defaultQuality < upperQualityNumber) {
|
||||||
|
this.selectedDefaultQuality = source.qualityLabel
|
||||||
|
}
|
||||||
|
} else if (qualityNumber === this.defaultQuality) {
|
||||||
|
this.selectedDefaultQuality = source.qualityLabel
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (this.selectedDefaultQuality === '') {
|
||||||
|
this.selectedDefaultQuality = this.sourceList[this.sourceList.length - 1].qualityLabel
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -273,7 +273,7 @@ export default Vue.extend({
|
||||||
const qualityA = parseInt(a.qualityLabel.replace('p', ''))
|
const qualityA = parseInt(a.qualityLabel.replace('p', ''))
|
||||||
const qualityB = parseInt(b.qualityLabel.replace('p', ''))
|
const qualityB = parseInt(b.qualityLabel.replace('p', ''))
|
||||||
return qualityA - qualityB
|
return qualityA - qualityB
|
||||||
})
|
}).reverse()
|
||||||
|
|
||||||
if (this.videoSourceList.length === 0) {
|
if (this.videoSourceList.length === 0) {
|
||||||
this.activeSourceList = result.player_response.streamingData.formats
|
this.activeSourceList = result.player_response.streamingData.formats
|
||||||
|
@ -285,7 +285,7 @@ export default Vue.extend({
|
||||||
this.upcomingTimestamp = upcomingTimestamp.toLocaleString()
|
this.upcomingTimestamp = upcomingTimestamp.toLocaleString()
|
||||||
} else {
|
} else {
|
||||||
this.videoLengthSeconds = parseInt(result.videoDetails.lengthSeconds)
|
this.videoLengthSeconds = parseInt(result.videoDetails.lengthSeconds)
|
||||||
this.videoSourceList = result.player_response.streamingData.formats
|
this.videoSourceList = result.player_response.streamingData.formats.reverse()
|
||||||
|
|
||||||
if (typeof result.player_response.streamingData.adaptiveFormats !== 'undefined') {
|
if (typeof result.player_response.streamingData.adaptiveFormats !== 'undefined') {
|
||||||
this.dashSrc = await this.createLocalDashManifest(result.player_response.streamingData.adaptiveFormats)
|
this.dashSrc = await this.createLocalDashManifest(result.player_response.streamingData.adaptiveFormats)
|
||||||
|
|
Loading…
Reference in New Issue