React坑太多,写个音效组件调一上午

zhuanbike 2022-1-5 737

import React, { Component } from 'react'
import { Button, Input, Icon,Dropdown,Card} from 'semantic-ui-react'
import { Link } from 'react-router-dom'
import $ from 'jquery'
import styles from './Home.scss'
import Modal from './Modal.jsx'
import MakeChannelModal from './MakeChannelModal.jsx'
class Music extends React.Component {
    constructor(props) {
    super(props);
    this.state = {
      play: false,
      pause: true
    };
    this.url = "http://streaming.tdiradio.com:8000/house.mp3";
    this.audio = new Audio(this.url);
    this.play = this.play.bind(this);
    this.pause = this.pause.bind(this);  }
  play(){
    this.setState({
      play: true,
      pause: false
    });
    console.log(this.audio);
    this.audio.play();
  }
  pause(){
  this.setState({ play: false, pause: true });
    this.audio.pause();
  }
  render() {
  return (
    <div>
      <button onClick={this.play}>Play</button>
      <button onClick={this.pause}>Pause</button>
    </div>
    );
  }
}
export default Music


最新回复 (1)
  • zhuanbike 2022-1-5
    0 引用 2
    感觉放弃了,继续vue吧
发新帖