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

onEnded calls twice #412

Closed
dmitryrn opened this issue May 31, 2018 · 0 comments
Closed

onEnded calls twice #412

dmitryrn opened this issue May 31, 2018 · 0 comments

Comments

@dmitryrn
Copy link

onEnded event calls twice and I do not understand why.

import React, { Component } from 'react'

import ReactPlayer from 'react-player'

class SingleClip extends Component {
  state = {
    currentUrl: '',
    currentStart: 0,
    currentEnd: 0,
    currentVideoIndex: 0,
  }

  componentWillMount = () => {
    const {
      videos,
    } = this.props

    const firstVideo = videos[0]

    this.setState({
      currentUrl: firstVideo.url,
      currentStart: firstVideo.start,
      currentEnd: firstVideo.end,
    })
  }

  onEnded = () => {
    const {
      currentVideoIndex,
    } = this.state

    const {
      videos,
    } = this.props

    const nextVideoIndex = currentVideoIndex + 1
    const nextVideoUrl = videos[nextVideoIndex].url
    
    console.log('url')

    this.setState({
      currentVideoIndex: nextVideoIndex,
      currentUrl: nextVideoUrl,
    }, () => console.log('state updated'))
  }

  render() {
    const {
      currentUrl,
      currentStart,
      currentEnd,
    } = this.state

    console.log('render')

    return (
      <div>
        <div>Single clip</div>
        <ReactPlayer
          ref={x => this.player = x}
          playing
          onEnded={this.onEnded}
          url={currentUrl}
          config={{
            youtube: {
              playerVars: {
                showinfo: 1,
                controls: 1,
                start: currentStart,
                end: currentEnd,
              }
            },
          }} />
      </div>
    )
  }
}

export default SingleClip

console.log output:

render
// waiting till video ends
url
render
state updated
url
render
state updated

props.videos:

[
  {
    url: 'https://www.youtube.com/watch?v=A71aqufiNtQ',
    start: 15,
    end: 20,
  }, {
    url: 'https://www.youtube.com/watch?v=pgAvVxowaYU',
    start: 30,
    end: 35,
  }, {
    url: 'https://www.youtube.com/watch?v=A71aqufiNtQ',
    start: 60,
    end: 70,
  },
]
@dmitryrn dmitryrn changed the title onEnded function calls twice onEnded calls twice May 31, 2018
david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue Dec 23, 2018
david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue May 23, 2020
albanqoku added a commit to albanqoku/react-player that referenced this issue Feb 24, 2021
Webmaster1116 added a commit to Webmaster1116/video-player that referenced this issue May 20, 2021
webmiraclepro added a commit to webmiraclepro/video-player that referenced this issue Sep 9, 2022
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

No branches or pull requests

1 participant