<commit_before>import React, {useEffect, useRef} from 'react';
import {media} from 'pageflow/frontend';

export function MediaPlayer(props){
  const playerWrapperRef = useRef(null);
  
  useEffect( () => {
    let playerWrapper = playerWrapperRef.current;
    if (props.sources) {
      let player = media.getPlayer(props.sources, {
        poster: props.poster,
        tagName: props.type
      });
      playerWrapper.appendChild(player.el());
      return () => {
        media.releasePlayer(player);
        playerWrapper.innerHTML = '';
        player.dispose();
      }
    }
  }, [props.sources, props.poster, props.type]);

  return (
    <div ref={playerWrapperRef}></div>
  );
}<commit_msg>implemented scrolltosectioncontext for media player<commit_after>import React, {useEffect, useRef, useContext} from 'react';
import {media} from 'pageflow/frontend';

import ScrollToSectionContext from "../ScrollToSectionContext";

export function MediaPlayer(props){
  const playerWrapperRef = useRef(null);
  let scrollToSection = useContext(ScrollToSectionContext);

  useEffect( () => {
    let playerWrapper = playerWrapperRef.current;
    if (props.sources) {
      let player = media.getPlayer(props.sources, {
        poster: props.poster,
        tagName: props.type
      });
      player.on('ended', function () {
        props.nextSectionOnEnd && scrollToSection('next');
      });
      let playerElement = player.el();      
      playerWrapper.appendChild(playerElement);
      
      return () => {
        media.releasePlayer(player);
        playerWrapper.innerHTML = '';
        player.dispose();
      }
    }
  }, [props.sources, props.poster, props.type, props.nextSectionOnEnd, scrollToSection]);

  return (
    <div className={props.className} ref={playerWrapperRef}>
    </div>
  );
}
{'fraction_non_alphanumeric': 0.1319712865819989, 'fraction_numerical': 0.0, 'mean_word_length': 3.184757505773672, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2767865', 'n_tokens_mistral': 519, 'n_tokens_neox': 516, 'n_words': 103}