Ext.define('SoundClass15', {
    extend:'GeneralAction',
    constructor:function (cfgXML, o, actionSequence) {
        this.Url = "";
        this.WaitUntilComplete = false;
        this.CancelType = CancelTypes.MouseClickOrAnyKey;
        this.Duration = 0;
        this.BadAudio = false;
        this.callParent([ cfgXML, o, actionSequence]);
        this.Url = Author.resourcePath + XmlHelper.getString(cfgXML, "mp3FileName");
        this.WaitUntilComplete = XmlHelper.getBoolean(cfgXML, "waitUntilComplete");
        this.CancelType = XmlHelper.getInteger(cfgXML, "cancelType");
        this.Duration = XmlHelper.getFloat(cfgXML, "duration");
        this.ProcessedToNextAction = false;
    },
    getAudioPause:function () {
        return new AuthorPause(this, WaitModes.WaitFor, this.Duration, this.CancelType, null, null);
    },
    onCancelledByAnotherAudio:function (audioObject) {
        // showDebugInfo("onCancelledByAnotherAudio: " + audioObject);
    },
    onCancelledByAnotherVideo:function (videoObject) {
        // showDebugInfo("onCancelledByAnotherVideo: " + videoObject);
    },
    onSkippedByUser:function () {
        // showDebugInfo("Sound skippedByUser: " + this.id);
        if (Author.DisplayManager.Pause && Author.DisplayManager.Pause.Source.id == this.id) {
            Author.DisplayManager.Pause = null;
        }
        window.clearTimeout(Author.DisplayManager.ActionTimer);
        Author.DisplayManager.processListActions();
    },
    onLoadedMetaData:function (duration) {
        this.Duration = duration;
    },
    onCanPlayThrough:function (duration) {
        this.Duration = duration;
        if (!this.WaitUntilComplete) {
            if (!this.ProcessedToNextAction) {
                this.ProcessedToNextAction = true;
                window.clearTimeout(Author.DisplayManager.ActionTimer);
                Author.DisplayManager.processListActions();
            }
        }
        else {
            if (Author.DisplayManager.Pause != null) {
               // Author.log(Author.DisplayManager.Pause);
            }
            Author.DisplayManager.Pause = this.getAudioPause();

        }
    },
    onPlay:function (duration) {
        this.Duration = duration;
        if (Author.VideoManager.hasPlayingVideo()) {
            Author.VideoManager.interruptPlayingVideoByAudio(this);
        }
        if (!this.WaitUntilComplete) {
            if (!this.ProcessedToNextAction) {
                this.ProcessedToNextAction = true;
                window.clearTimeout(Author.DisplayManager.ActionTimer);
                Author.DisplayManager.processListActions();
            }
        }
        else {
            if (Author.DisplayManager.Pause != null) {
               // Author.log(Author.DisplayManager.Pause);
            }
            Author.DisplayManager.Pause = this.getAudioPause();

        }
    },
    onPosition:function (position) {
    },
    onCompleted:function () {
        if (this.WaitUntilComplete) {
            if (Author.DisplayManager.Pause && Author.DisplayManager.Pause.Source.id == this.id) {
                Author.DisplayManager.Pause = null;
                window.clearTimeout(Author.DisplayManager.ActionTimer);
                Author.DisplayManager.processListActions();
            }
        }
    },
    onError:function (err) {
       // Author.log("SoundClass:onError:" + err);
        window.clearTimeout(Author.DisplayManager.ActionTimer);
        Author.DisplayManager.processListActions();
    },
    processAction:function () {
        this.ProcessedToNextAction = false;
        if (Author.AudioManager.IsAudioAvailable) {

            Author.AudioManager.play(this);

        }
        else {
            this.BadAudio = true;
            return {MoveOn:true, Interval:0};
        }
        this.IsProcessed = true;
        return {MoveOn:true, Interval:3600 * 24 * 1000};
    }
});


