<commit_before>import bindAll from 'lodash.bindall';
import PropTypes from 'prop-types';
import React from 'react';
import VM from 'scratch-vm';
import AudioEngine from 'scratch-audio';
import LibraryComponent from '../components/library/library.jsx';

import soundIcon from '../components/asset-panel/icon--sound.svg';

import soundLibraryContent from '../lib/libraries/sounds.json';

class SoundLibrary extends React.PureComponent {
    constructor (props) {
        super(props);
        bindAll(this, [
            'handleItemSelected',
            'handleItemMouseEnter',
            'handleItemMouseLeave'
        ]);
    }
    componentDidMount () {
        this.audioEngine = new AudioEngine();
        this.player = this.audioEngine.createPlayer();
    }
    componentWillReceiveProps (newProps) {
        // Stop playing sounds if the library closes without a mouseleave (e.g. by using the escape key)
        if (this.player && !newProps.visible) this.player.stopAllSounds();
    }
    handleItemMouseEnter (soundItem) {
        const md5ext = soundItem._md5;
        const idParts = md5ext.split('.');
        const md5 = idParts[0];
        const vm = this.props.vm;
        vm.runtime.storage.load(vm.runtime.storage.AssetType.Sound, md5).then(soundAsset => {
            const sound = {
                md5: md5ext,
                name: soundItem.name,
                format: soundItem.format,
                data: soundAsset.data
            };
            return this.audioEngine.decodeSound(sound);
        })
        .then(() => {
            this.player.playSound(soundItem._md5);
        });
    }
    handleItemMouseLeave () {
        this.player.stopAllSounds();<commit_msg>Use soundId coming back from decodeSound<commit_after>import bindAll from 'lodash.bindall';
import PropTypes from 'prop-types';
import React from 'react';
import VM from 'scratch-vm';
import AudioEngine from 'scratch-audio';
import LibraryComponent from '../components/library/library.jsx';

import soundIcon from '../components/asset-panel/icon--sound.svg';

import soundLibraryContent from '../lib/libraries/sounds.json';

class SoundLibrary extends React.PureComponent {
    constructor (props) {
        super(props);
        bindAll(this, [
            'handleItemSelected',
            'handleItemMouseEnter',
            'handleItemMouseLeave'
        ]);
    }
    componentDidMount () {
        this.audioEngine = new AudioEngine();
        this.player = this.audioEngine.createPlayer();
    }
    componentWillReceiveProps (newProps) {
        // Stop playing sounds if the library closes without a mouseleave (e.g. by using the escape key)
        if (this.player && !newProps.visible) this.player.stopAllSounds();
    }
    handleItemMouseEnter (soundItem) {
        const md5ext = soundItem._md5;
        const idParts = md5ext.split('.');
        const md5 = idParts[0];
        const vm = this.props.vm;
        vm.runtime.storage.load(vm.runtime.storage.AssetType.Sound, md5).then(soundAsset => {
            const sound = {
                md5: md5ext,
                name: soundItem.name,
                format: soundItem.format,
                data: soundAsset.data
            };
            return this.audioEngine.decodeSound(sound);
        })
        .then(soundId => {
            this.player.playSound(soundId);
        });
    }
    handleItemMouseLeave () {
        this.player.stopAllSounds();
{'fraction_non_alphanumeric': 0.11357664233576642, 'fraction_numerical': 0.004963503649635037, 'mean_word_length': 2.3424390243902438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4801857', 'n_tokens_mistral': 947, 'n_tokens_neox': 932, 'n_words': 210}