Skip to content
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: add volume and playback rate change notification feature to vid… #6473

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@
/* user-select is intentionally not disabled, so that you can select and copy the stats */
}

.valueChangePopup {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
padding: 10px;
border-radius: 5px;
font-size: 1.1em;
background-color: rgb(0 0 0 / 70%);
color: #fff;
width: 85px;
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
z-index: 2;
pointer-events: none;
}

.offlineWrapper {
position: absolute;
top: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,8 @@ export default defineComponent({
function changeVolume(step) {
const volumeBar = container.value.querySelector('.shaka-volume-bar')

const newValue = parseFloat(volumeBar.value) + (step * 100)
const oldValue = parseFloat(volumeBar.value)
const newValue = oldValue + (step * 100)

if (newValue < 0) {
volumeBar.value = 0
Expand All @@ -1808,6 +1809,16 @@ export default defineComponent({
}

volumeBar.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }))

let messageIcon
if (newValue <= 0) {
messageIcon = 'volume-mute'
} else if (newValue > 0 && newValue < oldValue) {
messageIcon = 'volume-low'
} else if (newValue > 0 && newValue > oldValue) {
messageIcon = 'volume-high'
}
showValueChange(`${Math.round(video.value.volume * 100)}%`, messageIcon)
}

/**
Expand All @@ -1822,6 +1833,9 @@ export default defineComponent({
if (newPlaybackRate > 0.07 && newPlaybackRate <= maxVideoPlaybackRate.value) {
video_.playbackRate = newPlaybackRate
video_.defaultPlaybackRate = newPlaybackRate

const playerPlaybackRate = player.getPlaybackRate() + step
showValueChange(`${playerPlaybackRate.toFixed(2)}x`)
ikizey marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -2047,7 +2061,12 @@ export default defineComponent({
// Toggle mute only if metakey is not pressed
if (!event.metaKey) {
event.preventDefault()
video_.muted = !video_.muted
const isMuted = !video_.muted
video_.muted = isMuted

const messageIcon = isMuted ? 'volume-mute' : 'volume-high'
const message = isMuted ? '0%' : `${Math.round(video_.volume * 100)}%`
showValueChange(message, messageIcon)
}
break
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.CAPTIONS:
Expand Down Expand Up @@ -2814,6 +2833,25 @@ export default defineComponent({

// #endregion functions used by the watch page

const showValueChangePopup = ref(false)
const valueChangeMessage = ref('')
const valueChangeIcon = ref(null)
let valueChangeTimeout = null

function showValueChange(message, icon = null) {
valueChangeMessage.value = message
valueChangeIcon.value = icon
showValueChangePopup.value = true

if (valueChangeTimeout) {
clearTimeout(valueChangeTimeout)
}

valueChangeTimeout = setTimeout(() => {
showValueChangePopup.value = false
}, 2000)
}

return {
container,
video,
Expand All @@ -2837,6 +2875,11 @@ export default defineComponent({
handleEnded,
updateVolume,
handleTimeupdate,

showValueChange,
ikizey marked this conversation as resolved.
Show resolved Hide resolved
valueChangeMessage,
valueChangeIcon,
showValueChangePopup
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
<span>{{ $t('Video.Player.Stats.Dropped Frames / Total Frames', stats.frames) }}</span>
</template>
</div>
<div
v-if="showValueChangePopup"
class="valueChangePopup"
>
<font-awesome-icon
v-if="valueChangeIcon"
:icon="['fas', `${valueChangeIcon}`]"
ikizey marked this conversation as resolved.
Show resolved Hide resolved
/>
{{ valueChangeMessage }}
</div>
<div
v-if="showOfflineMessage"
class="offlineWrapper"
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ import {
faUsers,
faUsersSlash,
faWifi,
faVolumeHigh,
faVolumeLow,
faVolumeMute,
faXmark
} from '@fortawesome/free-solid-svg-icons'
import {
Expand Down Expand Up @@ -232,6 +235,9 @@ library.add(
faUsers,
faUsersSlash,
faWifi,
faVolumeHigh,
faVolumeLow,
faVolumeMute,
faXmark,

// solid icons
Expand Down
Loading