1 7 8 package org.openlaszlo.iv.flash.commands; 9 10 import org.openlaszlo.iv.flash.parser.*; 11 import org.openlaszlo.iv.flash.api.*; 12 import org.openlaszlo.iv.flash.api.action.*; 13 import org.openlaszlo.iv.flash.api.sound.*; 14 import org.openlaszlo.iv.flash.api.shape.*; 15 import org.openlaszlo.iv.flash.util.*; 16 import org.openlaszlo.iv.flash.cache.*; 17 import org.openlaszlo.iv.flash.url.*; 18 19 import org.openlaszlo.iv.flash.context.Context; 20 import java.io.*; 21 22 28 29 public class MP3SoundCommand extends GenericCommand { 30 31 public MP3SoundCommand() { 32 } 33 34 public void doCommand( FlashFile file, Context context, Script parent, int frame ) throws IVException 35 { 36 38 String filename = getParameter( context, "filename", "" ); 39 boolean cache = getBoolParameter( context, "cache", false ); 40 boolean stream = getBoolParameter( context, "stream", false ); 41 boolean stopAction = getBoolParameter( context, "stopaction", true ); 42 int delay = getIntParameter( context, "delay", 0 ); 43 String instancename = getParameter( context, "instancename" ); 44 45 IVUrl url = IVUrl.newUrl( filename, file ); 46 47 Script script = getInstance().copyScript(); 48 49 FlashBuffer fob = (FlashBuffer) MediaCache.getMedia(url); 50 if( fob == null ) { 51 try { 52 fob = new FlashBuffer(url.getInputStream()); 53 MediaCache.addMedia(url, fob, fob.getSize(), cache); 54 } catch( IOException e ) { 55 throw new IVException(Resource.ERRCMDFILEREAD, new Object [] {filename, getCommandName()}, e); 56 } 57 } 58 59 Frame stopFrame = null; 60 61 try { 62 if( stream ) { 63 SoundStreamBuilder ssb = SoundStreamBuilder.newSoundStreamBuilder(fob, file.getFrameRate()); 64 SoundStreamHead head = ssb.getSoundStreamHead(); 65 66 parent.getFrameAt( frame ).addFlashObject( head ); 68 69 int frameCount = parent.getFrameCount(); 70 int f = frame; 71 SoundStreamBlock block; 72 73 while( ( block = ssb.getNextSoundStreamBlock() ) != null ) { 74 if( f >= frameCount ) { 75 parent.newFrame().addFlashObject( block ); 76 } else { 77 parent.getFrameAt( f ).addFlashObject( block ); 78 } 79 80 f++; 81 } 82 83 getInstance().def = Shape.newEmptyShape1(); 84 85 stopFrame = parent.getFrameAt( f - 1 ); 86 } else { 87 MP3Sound sound = MP3Sound.newMP3Sound(fob); 88 if( delay != 0 ) { 90 sound.setDelaySeek( delay ); 91 } 92 93 SoundInfo soundInfo = SoundInfo.newSoundInfo( 0 ); 94 StartSound startSound = StartSound.newStartSound( sound, soundInfo ); 95 96 Frame newFrame = script.newFrame(); 97 newFrame.addFlashObject( startSound ); 98 99 stopFrame = newFrame; 100 } 101 } catch( IOException e ) { 102 throw new IVException(Resource.ERRCMDFILEREAD, new Object [] {filename, getCommandName()}, e); 103 } 104 105 if( instancename != null ) { 106 getInstance().name = instancename; 107 } 108 109 if( stopAction ) { 110 stopFrame.addStopAction(); 111 } 112 } 113 } 114 | Popular Tags |