import flash.external.ExternalInterface; class MiniStreamer extends MovieClip { public static var linkage:String = (linkage="__Packages.MiniStreamer")+(Object.registerClass(linkage,MiniStreamer)?"":""); private var __width:Number;// = 60; private var __height:Number;// = 4; private var _streaming:Boolean = true; private var _playing:Boolean = false; private var progress:Number; private var pc:MovieClip; private var sound:Sound; private var soundClip:MovieClip; public function MiniStreamer() { initializeInterface(); } private function initializeInterface():Void { if (ExternalInterface.available) { ExternalInterface.addCallback("playAudio", this, onPlay); ExternalInterface.addCallback("stopAudio", this, onStop); //ExternalInterface.addCallback("rewind", this, onRewind); } } private function layout():Void { if (!pc) pc = createEmptyMovieClip("pc", 1); pc.clear(); pc.lineStyle(0, 0, 0); pc.beginFill(0xe0e0e0, 100); pc.moveTo(0, 0); pc.lineTo(__width, 0); pc.lineTo(__width, __height); pc.lineTo(0, __height); pc.lineTo(0, 0); pc.endFill(); pc.beginFill(0x555555, 100); pc.lineTo(__width * (progress ? progress : 0), 0); pc.lineTo(__width * (progress ? progress : 0), __height); pc.lineTo(0, __height); //pc.lineTo(0, 0); pc.endFill(); } private function loadURL(str:String):Void { if (!soundClip) { soundClip = this.createEmptyMovieClip("soundClip", 0); } sound = new Sound(soundClip); sound.stop(); sound.loadSound(str, streaming); _playing = true; checkWatcher(); } private function checkWatcher():Void { if (_playing) { var f:Function = watchSound; var o:Object = this; soundClip.onEnterFrame = function() { return f.apply(o, arguments); }; } else soundClip.onEnterFrame = null; watchSound(); } function watchSound():Void { progress = sound.position / sound.duration; layout(); } private function onPlay(url:String):Void { if (url.length > 0) loadURL(url); } private function onStop():Void { sound.stop(); sound.position = 0; _playing = false; checkWatcher(); } public function setSize(w:Number, h:Number):Void { __width = w; __height = h; layout(); } public function set streaming(b:Boolean):Void { _streaming = b; } public function get streaming():Boolean { return _streaming; } }