<commit_before>var React = require('react');
var MediaObject = require('../viewer/models/media-object.jsx');
var lodash = require('lodash');
var VideoMediaObject = require('../../utils/media-object/video-media-object');
var ImageMediaObject = require('../../utils/media-object/image-media-object');
var TextMediaObject = require('../../utils/media-object/text-media-object');
var variableThrottle = require('../../utils/variable-throttle');
var hat = require('hat');

var RandomVisualPlayer = React.createClass({
    getInitialState: function () {
        return {
            queue: [],
            arr: [],
            mediaQueue: {},
            interval: false
        };
    },

    loadMediaObject: function (queue) {
        var self = this;

        lodash.forEach([VideoMediaObject, ImageMediaObject, TextMediaObject], function (moType) {

            var obj = queue.mediaQueue.take([moType]);
            if (obj != undefined) {
                obj.guid = obj.guid || hat();
                self.state.arr.push(obj);
            }
        });

                // APEP refactored to avoid async issues
                var q = self.state.arr.map(function (mediaObject, index) {
                    var data = {
                        mediaObject: mediaObject,
                        player: self.refs.player,
                        //Attach the done handler using react props
                        moDoneHandler: self.moDoneHandler,
                        displayDuration: self.props.mediaQueue.displayDuration,
                        transitionDuration: self.props.mediaQueue.transitionDuration,
                        key: index
                    };

                    return (
                        <MediaObject key={mediaObject.guid} data={data} onRef={function(ref){
                            mediaObjectRefs[mediaObject.guid] = ref
                        }}></MediaObject>
                    );
                });
                self.setState({mediaQueue: self.props.mediaQueue, queue: q});
    },

    moDoneHandler: function (mediaObject) {

        console.log("randomVisualPlayer - moDoneHandler - mediaObject: ", mediaObject.props.data.mediaObject);

        // APEP for any non video type media, we can similarly clear the video media object
        if (mediaObject.props.data.mediaObject.type !== "video") {
            this.clearMediaObject(mediaObject);
            return;
        }

        // APEP video done handler must be handled separately for autoreplay feature
        this.vmoDoneHandler(mediaObject)
    },

    vmoClearActiveFromQueue: function(videoMediaObject) {
        // APEP required for vanilla JS objects queue to be cleared of this active vmo ( need to review this )
        videoMediaObject.props.data.mediaObject.emit("done", videoMediaObject.props.data.mediaObject);
    },

    vmoAtEndOfLooping: function(videoMediaObject, vmo) {

        this.clearMediaObject(videoMediaObject);
        this.vmoClearActiveFromQueue(videoMediaObject);
    },

    vmoWithAutoReplayZeroOrOne: function (videoMediaObject, vmo) {

        this.clearMediaObject(videoMediaObject);
        this.vmoClearActiveFromQueue(videoMediaObject);
    },

    vmoDoneHandler: function (videoMediaObject) {
        var self = this;

        var vmo = videoMediaObject.props.data.mediaObject;

        console.log("randomVisualPlayer - vmoDoneHandler - vmo: ", vmo);

        if (vmo._obj.autoreplay === 0 || vmo._obj.autoreplay === 1) {
            self.vmoWithAutoReplayZeroOrOne(videoMediaObject, vmo);
            return;
        }
        if (vmo.currentLoop == undefined) {
            videoMediaObject.props.data.mediaObject.currentLoop = 1;
            //TODO if not vimeo
             videoMediaObject.play();
        } else if (vmo.currentLoop < vmo._obj.autoreplay) {
            videoMediaObject.props.data.mediaObject.currentLoop++;<commit_msg>Resolved some missing work from the playback fixes for scene playback and graph scene list playback<commit_after>var React = require('react');
var MediaObject = require('../viewer/models/media-object.jsx');
var lodash = require('lodash');
var VideoMediaObject = require('../../utils/media-object/video-media-object');
var ImageMediaObject = require('../../utils/media-object/image-media-object');
var TextMediaObject = require('../../utils/media-object/text-media-object');
var variableThrottle = require('../../utils/variable-throttle');
var hat = require('hat');

var mediaObjectRefs = {};

var RandomVisualPlayer = React.createClass({
    getInitialState: function () {
        return {
            queue: [],
            arr: [],
            mediaQueue: {},
            interval: false
        };
    },

    loadMediaObject: function (queue) {
        var self = this;

        lodash.forEach([VideoMediaObject, ImageMediaObject, TextMediaObject], function (moType) {

            var obj = queue.mediaQueue.take([moType]);
            if (obj != undefined) {
                obj.guid = obj.guid || hat();
                self.state.arr.push(obj);
            }

            // APEP refactored to avoid async issues
            var q = self.state.arr.map(function (mediaObject, index) {
                var data = {
                    mediaObject: mediaObject,
                    player: self.refs.player,
                    //Attach the done handler using react props
                    moDoneHandler: self.moDoneHandler,
                    displayDuration: self.props.mediaQueue.displayDuration,
                    transitionDuration: self.props.mediaQueue.transitionDuration,
                    key: index
                };

                return (
                    <MediaObject key={mediaObject.guid} data={data} onRef={function(ref){
                            mediaObjectRefs[mediaObject.guid] = ref
                        }}></MediaObject>
                );
            });
            self.setState({mediaQueue: self.props.mediaQueue, queue: q});
        });
    },

    moDoneHandler: function (mediaObject) {

        console.log("randomVisualPlayer - moDoneHandler - mediaObject: ", mediaObject.props.data.mediaObject);

        // APEP for any non video type media, we can similarly clear the video media object
        if (mediaObject.props.data.mediaObject.type !== "video") {
            this.clearMediaObject(mediaObject);
            return;
        }

        // APEP video done handler must be handled separately for autoreplay feature
        this.vmoDoneHandler(mediaObject)
    },

    vmoAtEndOfLooping: function(videoMediaObject, vmo) {

        this.clearMediaObject(videoMediaObject);
    },

    vmoWithAutoReplayZeroOrOne: function (videoMediaObject, vmo) {

        this.clearMediaObject(videoMediaObject);
    },

    vmoDoneHandler: function (videoMediaObject) {
        var self = this;

        var vmo = videoMediaObject.props.data.mediaObject;

        console.log("randomVisualPlayer - vmoDoneHandler - vmo: ", vmo);

        if (vmo._obj.autoreplay === 0 || vmo._obj.autoreplay === 1) {
            self.vmoWithAutoReplayZeroOrOne(videoMediaObject, vmo);
            return;
        }
        if (vmo.currentLoop == undefined) {
            videoMediaObject.props.data.mediaObject.currentLoop = 1;
            //TODO if not vimeo
             videoMediaObject.play();
        } else if (vmo.currentLoop < vmo._obj.autoreplay) {
            videoMediaObject.props.data.mediaObject.currentLoop++;
{'fraction_non_alphanumeric': 0.11054398925453324, 'fraction_numerical': 0.0008059100067159167, 'mean_word_length': 2.059161873459326, 'pattern_counts': {'":': 0, '<': 9, '<?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': '669550', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1902, 'n_words': 408}