A volume slide will decrease to zero if the 'mute' button is selected

Well, the title pretty much sums it up.

I successfully managed to make it so that when you slide the volume to 0, it mutes the video. However, I am struggling with achieving this: if the video is muted, the volume slider should automatically move to 0.

I have tried various combinations of code but I can't seem to wrap my head around it.

Here is the HTML snippet:

     <div class="controls">
              <span class="columns small-8 medium-6 text-left">
                <span *ngIf="!playing" class="playpause" (click)="videoHandler('play')">
                  <i class="fa fa-play" aria-hidden="true" ></i>
                </span>
                <span *ngIf="playing" class="playpause" (click)="videoHandler('pause')">
                  <i class="fa fa-pause" aria-hidden="true" ></i>
                </span>
                <span *ngIf="!muted" class="speaker" (click)="videoHandler('mute')">
                  <i class="fa fa-volume-up" aria-hidden="true" ></i>
                </span>
                <span *ngIf="muted" class="speaker" (click)="videoHandler('unmute')">
                  <i class="fa fa-volume-off" aria-hidden="true" ></i>
                </span>
                <span class="volumeslider">
                  <input type="range" name="volume" min="0" max="1" step="0.05" value="1" (input)="videoHandler('volume', $event)">
                </span>
              </span>
            </div>

The TypeScript code snippet:

public videoHandler(fn: any, e: any): void {
    let element = this.videoplayer.nativeElement;

    switch (fn) {
        case 'play':
            element.play();
            this.playing = true;
            break;
        case 'pause':
            element.pause();
            this.playing = false;
            break;
        case 'fullscreen':
            if (element.requestFullscreen) {
                element.requestFullscreen();
            } else if (element.mozRequestFullScreen) {
                element.mozRequestFullScreen();
            } else if (element.webkitRequestFullscreen) {
                element.webkitRequestFullscreen();
            }
            break;
        case 'mute':
            element.muted = true;
            this.muted = true;
            break;
        case 'unmute':
            element.muted = false;
            element.removeAttribute('muted');
            this.muted = false;
            break;
        case 'volume':
            element.volume = e.target.value;
            this.muted = e.target.value === '0';
            element.muted = e.target.value === '0';
            break;
        case 'download':
            let src = e.target.dataset.vsr;
            let id = e.target.dataset.vid;
            this.downloadEmitter.emit({
                video: src,
                video_id: id
            });
        default:
            break;
    }
}

It seems like a simple problem, but after staring at it for days, fresh new ideas are hard to come by.

Answer №1

If you find yourself in need of this solution later on, the answer is quite simple. Here is the code snippet:

 <div class="controls">
          <span class="columns small-8 medium-6 text-left">
            <span *ngIf="!playing" class="playpause" (click)="videoHandler('play')">
              <i class="fa fa-play" aria-hidden="true" ></i>
            </span>
            <span *ngIf="playing" class="playpause" (click)="videoHandler('pause')">
              <i class="fa fa-pause" aria-hidden="true" ></i>
            </span>
            <span *ngIf="!muted" class="speaker" (click)="videoHandler('mute'); slider.value = 0" >
              <i class="fa fa-volume-up" aria-hidden="true" ></i>
            </span>
            <span *ngIf="muted" class="speaker" (click)="videoHandler('unmute'); slider.value = 1">
              <i class="fa fa-volume-off" aria-hidden="true" ></i>
            </span>
            <span class="volumeslider">
              <input type="range" name="volume" min="0" max="1" step="0.05" value="1" (input)="videoHandler('volume', $event); slider.value = $event.target.value" class="volumeslide" #slider>
            </span>
          </span>
   </div>

One crucial detail I overlooked was including slider.value = number when muting or unmuting.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The error you are seeing is a result of your application code and not generated by Cypress

I attempted to test the following simple code snippet: type Website = string; it('loads examples', () => { const website: Website = 'https://www.ebay.com/'; cy.visit(website); cy.get('input[type="text"]').type(& ...

Issues with rendering alpha transparency correctly in Three.js png textures can be frustrating. Sometimes, the alpha

For my project, I am working on creating a cube and applying 6 different textures to each of its faces. These textures are .png files with transparent parts. Additionally, I want to apply a color to the cube and have that color show through the transparent ...

Manipulating links using JQuery: avoiding the binding of new links

I need to update a website with 50 pages that currently doesn't use ajax, making it cumbersome to make edits since changes have to be made on all 50 pages individually. After removing duplicate HTML from all 50 pages, I'm facing some issues: fu ...

The static files are being received by Django but are not functioning properly

I've been working on a project using django 1.7, and below is my settings.py configuration: STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, "assets"), ) STATIC_ROOT = "absolute/path/to/static" In the 'assets&apo ...

Setting the content-type for static assets in NuxtJS

I'm trying to use the Nuxt built-in server to serve the static file /.well-known/apple-app-site-association with a content-type of application/json. Unfortunately, because the file does not have a .json extension, it is returning as application/octet- ...

The storage does not reflect updates when using redux-persist with next-redux-wrapper in a Typescript project

I'm currently working on integrating redux-persist with next.js using next-redux-wrapper. However, I'm facing an issue where the storage is not updating and the state is lost during page refresh. Below is my store.ts file: import { createStore, ...

Ensuring Mongoose Schema complies with an external API

My database schema includes a mongoose User schema with the following structure: const User: Schema = new Schema({ // some other fields email: {type: String, unique: true, require: true, validate: [myValidator, 'invalid email provided'], // some ...

What is the best way to implement a subquery using EXISTS in Knex?

I'm currently facing challenges while constructing a query using knex, specifically when it comes to incorporating the 'WHERE' clause with the condition EXISTS (SELECT * FROM caregiver_patient WHERE patient_id IN (0,1)). Below is the origin ...

Reorganize the JSON data to match the specified format

{ "EUR": { "Description": "", "Bid": "1.1222", "Region": "", "Bid1": "1.1283", "CurrencyCode": "EUR", "FeedSource": "1", "Ask": "1.1226", "ProviderName": "TEST 1", "Low": "1.1195", ...

npm: generate new script directive

When I start up my NodeJs (ES6) project, I usually enter the following command in the console: ./node_modules/babel/bin/babel-node.js index.js However, I wanted to streamline this process by adding the command to the scripts section of my package.json fi ...

What is the best way to integrate the retry functionality from Rxjs into my await function?

When calling an await function in my code block, if it fails on the first try, I need to retry it. If it fails again on the second try, I want to display an error message. BELOW IS MY CODE SNIPPET async makeCall(inputs: myInputs): Promise<Instance> ...

Issues with CSS and Node Express

I'm currently experimenting with some code and running into a problem. Using Express, I noticed that only the CSS selector for the body element is working. However, if I remove the body tag, then the next container works, but the ones after that do n ...

Are there alternative methods to navigate in Angular 6 that are similar to the navigation in Ionic 3?

I'm currently facing an issue with navigation in Angular 6. In Ionic, we can navigate to a different page by using navCtrl.push('ExamplePage'); However, in Angular 6, I am having trouble navigating through a button click like this: app.co ...

Running the nestjs build command is impossible without the existence of the node_modules folder

Currently, I am in the process of creating a Nestjs micro-service and everything is going smoothly. To run the build found within the dist folder, I use the command below: node dist/main.js However, I encountered a problem where this command does not exec ...

Is my Javascript experiencing a shortage of asyncIds? (Encountered RangeError in inspector_async_hook.js)

One issue that I frequently encounter while using async/await is the following error: RangeError: Value undefined out of range for undefined options property undefined at Set.add (<anonymous>) at AsyncHook.init (internal/inspector_async_hook ...

Maintaining Scene Integrity in THREE.JS: Tips for Handling Window Resizing

My layout includes a div with a scene that looks great initially; however, as soon as I start moving or resizing the window, the scene overflows the boundaries of the div and goes haywire, almost filling the entire window. Are there any techniques or solu ...

What is the reason behind caching form data in an ajax call?

After the first successful submission, I am facing an issue where the original form data is being re-sent even when new values are submitted for a second attempt. How can I reset and reload the data to avoid this problem? I have tried several approaches i ...

Crosswalk code unable to detect electronic devices

The implementation of a rails application involves the following code snippet: <div id="sourceSelectPanel" style="display:none"> <label for="sourceSelect"& gt;Change video source:& lt;/label> <select id=" ...

Angular doesn't properly update Highcharts

Currently, I am facing an issue with updating my Highcharts chart dynamically based on an observable configuration in an Angular component. I have implemented an observable with ngIf as shown below: <highcharts-chart *ngIf="conf | async as option ...

How can I create a detailed highchart map of Korea that accurately includes Dokdo in its design?

I am currently working on a project to create a comprehensive map of Korea using highchart. One major challenge I have encountered is the absence of Dokdo on the standard map of Korea provided by highchart. Is there a way for me to develop a map that inc ...