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

Add mid and low volume icons #159

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rtritto
Copy link
Contributor

@rtritto rtritto commented Feb 23, 2025

Fix #158

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

TODO

Draft for core/player.ts:

/**
 * On the player is ready
 */
onReady() {
  this.options.muted && this.mute()
  this.media.classList.add('v-media')

  // The iframe needs to be ignored by the focus
  this.media.setAttribute('tabindex', '-1')

  // If player has autoplay option, play now
  if (this.options.autoplay) {
    // Autoplay on video is authorize only when the media element is muted
    !this.media.muted && this.mute()

    this.play()
  }

  this.Vlitejs.onReady instanceof Function && this.Vlitejs.onReady.call(this, this)

  if (this.media.preload === 'none' && this.Vlitejs.provider === 'html5') {
    this.media.addEventListener('loadedmetadata', () => this.triggerOnReady())
  } else {
    this.triggerOnReady()
  }
  this.loading(false)

+  this.elements.volume!.addEventListener('volumechange', (event: Event) => {
+    const iconVolume = document.querySelector('.iconVolume')!
+    iconVolume.classList.remove('v-vol-0', 'v-vol-1', 'v-vol-2', 'v-vol-3')
+    const { volume } = event as unknown as { volume: number }
+    if (volume === 0) {
+      iconVolume?.classList.add('v-vol-0')  // Mute icon
+    } else if (volume < 0.3) {
+      iconVolume?.classList.add('v-vol-1')  // Low volume icon
+    } else if (volume > 0.7) {
+      iconVolume?.classList.add('v-vol-3')  // High volume icon
+    } else {
+      iconVolume?.classList.add('v-vol-2')  // Mid volume icon
+    }
+  })
}

// ...

/**
 * Unmute the volume on the media element
 */
unMute() {
  this.methodUnMute()
  this.isMuted = false

  if (this.elements.volume) {
    this.elements.volume.classList.remove('v-controlPressed')
    this.elements.volume.setAttribute('aria-label', 'Mute')
  }

-    this.dispatchEvent('volumechange')
+  this.dispatchEvent('volumechange', {
+    volume: this.getVolume().then((volume: number) => volume)  // pass the volume value to change into the related volume icon
+  })
}

Copy link

vercel bot commented Feb 23, 2025

@rtritto is attempting to deploy a commit to the Vlitejs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Icons for volume level
1 participant