#include "drawRect.as" Stage.align = 'TL'; h = 0; w = 0; // create some defaults for when they don't put it in URL if (width == void(0)) { width = 320; } if (height == void(0)) { height = 240; } function newbox(mc, w, h, offset) { if (offset == void(0)) { offset = 0; } mc.clear(); mc.lineStyle (2, 0x6688AA); mc.beginFill (0xAABBCC, 50); mc.drawRect (0, 0 - offset, w, h + offset, 6); mc.endFill (); //updateAfterEvent (); } mc = _root.createEmptyMovieClip('timeline_scrubber', _root.getNextHighestDepth()); mc.clear(); mc.lineStyle (2, 0x6688AA); mc.beginFill (0xAABBCC, 50); mc.drawRect (-2, 5, 2, 14, 1); mc.endFill (); // this is amended to set the video size to a fixed multiple function redolayout(force) { if (w != Stage.width || h != Stage.height || force != void(0)) { w = Stage.width; h = Stage.height; // the area available for video is full width but 32px less than height var sh = h - 32; var sw = w; // find scalings that work. the smallest scale is used so everything fits // on screen scalew = int(sw / width); scaleh = int(sh / height); scale = Math.min(scalew, scaleh); // if the scale is 0, the screen size is less than native, so work the // other way round and see what our best divisor is. this time we're looking // for the smallest value to maximise the area. if (scale == 0) { scalew = int(width / sw + 0.5); scaleh = int(height / sh + 0.5); scale = 1 / Math.max(scalew, scaleh); } else { // don't scale up from native scale = 1; } // now try scaling the video to fit the area var vw = int(width * scale); var vh = int(height * scale); /* var vw = width * sh / height; var vh = sh; if (vw > sw) { vh = height * sw / width; vw = sw; } */ var ox = int((sw - vw) / 2); var oy = int((sh - vh) / 2); display.video._width = vw; display.video._height = vh; display._x = ox; display._y = oy; _root.pause._x = ox + 32; _root.pause._y = h - 28; newbox(_root['pause'], 24, 24); _root.play._x = ox + 4; _root.play._y = h - 28; newbox(_root['play'], 24, 24); _root.displaytime._x = ox + vw - 84 - 32; _root.displaytime._y = h - 28; newbox(_root.displaytime, 80, 24); _root.timeline_scrubber._y = h - 28; _root.sound._x = ox + vw - 32; _root.sound._y = h - 28; newbox(_root.sound, 24, 24); _root.timeline._x = ox + 60; _root.timeline._y = h - 28; newbox(_root.timeline, vw - 148 - 32, 24); playback_position._x = ox + 66; playback_position._y = h - 22; bytes_loaded._x = ox + 66; bytes_loaded._y = h - 22; progressbandwidth = vw - 148 - 32 - 12; //_root.timeline._width - 24; //var s = ''; //for (c in _root.timeline) { // s = s + c + "\n"; //} //_root.dummy = s; updateAfterEvent(); } } redolayout(); checklayout = setInterval(redolayout, 500); // check the characters in the supplied video name match convention // I've allow path specification, but no . so directory traversal is // restricted pattern = 'abcdefghijklmnopqrstuvwxyz0123456789-_/.'; error = false; dummy = video; for (c = 0; c < video.length; c++) { if (pattern.indexOf(video.substr(c, 1).toLowerCase()) < 0) { error = true; } } if (error) { video = ''; } //var video:Video; // my_video is a Video object on the Stage nc = new NetConnection(); nc.connect(null); ns = new NetStream(nc); ns.setBufferTime(5.0); ns.onMetaData = function(infoObject:Object) { _root.videolength = infoObject.duration; // if the video clip has info on its own size, use it var redo = false; if (infoObject.width != void(0)) { _root.width = infoObject.width; redo = true; } if (infoObject.height != void(0)) { _root.height = infoObject.height; redo = true; } var s = ''; for (c in infoObject) { s = s+c+':'+infoObject[c]+"\n"; } _root.dummy = s; if (redo) { redolayout(true); } } //Stage.width = width + 8; //Stage.height = height + 32; display.video.attachVideo(ns); ns.play(video); //ns.pause(true); //ns.seek(0); /* ns.onStatus = function(infoObject:Object) { dummy = dummy + ("NetStream.onStatus called: ("+getTimer()+" ms)"); for (var prop in infoObject) { dummy = dummy + ("\t"+prop+":\t"+infoObject[prop]+"\n"); } dummy = dummy + "\n\n"; }; */ pause.onRelease = function() { ns.pause(true); } play.onRelease = function() { if (ns.time >= (_root.videolength-1)) { ns.seek(0); } ns.pause(false); } timeline.onPress = function() { reposition = true; lasttimepos = -1; } timeline.onRelease = function() { reposition = false; lasttimepos = -1; } timeline.onReleaseOutside = function() { reposition = false; lasttimepos = -1; } /* timeline.onEnterFrame = function() { if (reposition) { var x = _xmouse - _root.timeline._x - 6; timepos = Math.max(0, Math.min(_root.videolength, x * _root.videolength / progressbandwidth)); if (timepos != lasttimepos) { ns.seek(); } lasttimepos = timepos; } } */ function fmt_time(n) { var s = String(int(n % 60)); if (s.length < 2) { s = "0"+s; } s = String(int(n / 60))+':'+s; return s; } function ticker():Void { var bl = int(ns.bytesLoaded * progressbandwidth / ns.bytesTotal); if (bytes_loaded._width <> bl) { bytes_loaded._width = bl; } if (ns.time > _root.videolength) { _root.videolength = ns.time; } var pl = int(ns.time * progressbandwidth / _root.videolength); if (playback_position._width <> pl) { playback_position._width = pl; timeline_scrubber._x = playback_position._x + pl; } timedisplay = fmt_time(ns.time)+'/'+fmt_time(_root.videolength); //dummy = ns.time + '/' + _global.videolength; if (reposition) { var x = _root._xmouse - _root.timeline._x - 6; timepos = Math.max(0, Math.min(_root.videolength, x * _root.videolength / progressbandwidth)); if (timepos != lasttimepos) { ns.seek(timepos); } lasttimepos = timepos; } } _global.tickerId = setInterval(this, "ticker", 100); stop();