// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:06:18
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/commands/MP3SoundCommand

package com.macromedia.generator.commands;

import com.macromedia.generator.api.*;
import com.macromedia.generator.app.*;
import java.util.Properties;

public class MP3SoundCommand extends GenericCommand
{

    public MP3SoundCommand()
    {
    }

    public void doCommand(FlashEnvironment flashenvironment, Script script, Context context, int i, Properties properties)
        throws FlashCommandException
    {
        int j = 0;
        int k = 0;
        boolean flag = true;
        _fld0109 = new GenVector(16);
        Script script1 = (Script)_fld0109.add(script.getCommandScript(i));
        String s = properties.getProperty("filename", "");
        String s1 = properties.getProperty("stream", "true");
        String s2 = properties.getProperty("fps", "12");
        String s3 = properties.getProperty("delay", "0");
        String s4 = properties.getProperty("cache", "false");
        String s5 = properties.getProperty("instancename", "");
        s = context.apply(s);
        s1 = context.apply(s1);
        s2 = context.apply(s2);
        s3 = context.apply(s3);
        s4 = context.apply(s4);
        s5 = context.apply(s5);
        try
        {
            j = Integer.valueOf(s2).intValue();
            if(j < 1 || j > 30)
            {
                logError(flashenvironment, "InvalidFrames", s2);
                j = 12;
            }
        }
        catch(NumberFormatException _ex)
        {
            logError(flashenvironment, "InvalidFrames", s2);
            j = 12;
        }
        try
        {
            k = Integer.valueOf(s3).intValue();
            if(k < 0 || k > 30)
            {
                logError(flashenvironment, "InvalidDelay", "");
                k = 0;
            }
        }
        catch(NumberFormatException _ex)
        {
            logError(flashenvironment, "InvalidDelay", "");
            k = 0;
        }
        if(s1.equalsIgnoreCase("false"))
            flag = false;
        else
        if(s1.equalsIgnoreCase("true"))
        {
            flag = true;
        } else
        {
            logError(flashenvironment, "InvalidStream", "");
            flag = true;
        }
        Object obj = null;
        try
        {
            CacheManager cachemanager = flashenvironment.getCacheManager();
            if(cachemanager != null)
            {
                boolean flag1 = false;
                if(s4.equalsIgnoreCase("true"))
                    flag1 = true;
                obj = cachemanager.getMediaData(flashenvironment, s, flag1);
            }
            if(obj == null)
                throw new GeneratorApiException("unable to open file");
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToOpenFile", s);
            _fld0109.release();
            return;
        }
        Script script2;
        try
        {
            Buffer buffer = new Buffer();
            Buffer buffer1 = new Buffer();
            buffer.write((byte[])obj);
            script1.MP3convert(buffer, buffer1, 0, flag ? 1 : 0, j, 0, -1);
            script2 = (Script)_fld0109.add(new Script());
            script2.setFileVersion(script.getFileVersion());
            script2.setBuffer(buffer1);
            buffer1.release();
            buffer.release();
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToOpenFile", s);
            _fld0109.release();
            return;
        }
        try
        {
            int l = script2.getLastFrame();
            int i1 = k * (int)script.getFrameRate();
            Matrix matrix = (Matrix)_fld0109.add(new Matrix());
            Action action = new Action();
            action.addStop();
            script2.insertAction(action, l);
            script1.insertAction(action, l + i1);
            script1.insertScript(script2, 0, i1, matrix, l + i1, matrix);
            if(s5 != null)
                script.setCommandLabel(i, s5);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToInsertFile", s);
        }
        _fld0109.release();
    }

    GenVector _fld0109;
}