Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

play 2 audio react

import React from 'react';
import playIcon from './images/play.png';
import pauseIcon from './images/pause.png';
import globalAudio from './globalAudio';

class Music extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 'play': false };
        this.name = props.src;
        this.togglePlay = this.togglePlay.bind(this);
    }

    togglePlay() {
        this.setState({'play': !this.state.play}, () => {
            this.state.play ? globalAudio.play(this.name) : globalAudio.pause(this.name);
        });
    }

    componentWillUnmount () {
        globalAudio.pause(this.name);
    }

    render() {
        return (
            <div style={this.props.style} className={this.props.className}>
                {this.state.play
                    ? <button className="audio-button" aria-label="Pause" onClick={this.togglePlay}><img src={pauseIcon} width="34" height="34" alt="Pause"></img></button>
                    : <button className="audio-button" aria-label="Play" onClick={this.togglePlay}><img src={playIcon} width="34" height="34" alt="Play"></img></button>}
            </div>
        );
    }
}

export default Music;
Comment

PREVIOUS NEXT
Code Example
Javascript :: add codegrepper 
Javascript :: nextjs error can not find next/bable 
Javascript :: add content in textarea by clicking on button 
Javascript :: can you push more than one item javascript 
Javascript :: Find speacific object from an array in javascript 
Javascript :: react date component with word month 
Javascript :: invite tracker node.js v13 
Javascript :: cache management in angular 7 
Javascript :: google distance value to km convert 
Javascript :: Check for particular values in the response body 
Javascript :: select not input elements text JS 
Javascript :: build class component react 
Javascript :: how to set the id attr to a var in reactjs 
Javascript :: requiere and get a property simplified with Node 
Javascript :: shopify functions nodejs 
Javascript :: Calculate Grains on a given square on a chessboard js 
Javascript :: javasript vetical menu cog 
Javascript :: double bitwise not shorthand javascript 
Javascript :: how to find prime factors of a number in javascript 
Javascript :: ASPxGridView - How to trigger the CustomButtonCallback event 
Javascript :: get nearest to user location js 
Javascript :: foreach doesnt return 
Javascript :: how to add class to only one selected row then remove it after selecting it again 
Javascript :: javascript get element by class domlist undefined 
Javascript :: 5.1.3. Boolean Expressions&para; 
Javascript :: add textbox data to table html and javascript 
Javascript :: p5 js stop video camera capture 
Javascript :: how to test conditional rendering vue test utils 
Javascript :: get all keys of nested object json data javascript 
Javascript :: Example to adds two colour palettes to the sidebar in wordpress 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =