TEXTp mode?
@see http://youtubejpblog.blogspot.com/2010/03/textp-youtube.html
*
* IMPORTANT!!!
* This sample ONLY WORKS AT LOACAL CONTEXT
* because of the security related problem.
* For now, plz download this source code
* and preview at local machine.
*
* Is there any way to avoid this problem???
*
* And needs some optimization.
*
*
* 重要!!!
* このサンプルはローカルのセキュリティ関連の問題により、
* コンテキストでしか動きません。今のところ、ソースコード
* をダウンロードしてローカルのマシンで見てもらうしか
* ありません。
*
* どうすれば、この手の問題を回避出来るのでしょう?
*
* そして、最適化も必要ですね。
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7Htn
*/
// forked from kei1975's forked from: YouTube apiplayer
// forked from psyark's YouTube apiplayer
/**
* @see http://youtubejpblog.blogspot.com/2010/03/textp-youtube.html
*
* IMPORTANT!!!
* This sample ONLY WORKS AT LOACAL CONTEXT
* because of the security related problem.
* For now, plz download this source code
* and preview at local machine.
*
* Is there any way to avoid this problem???
*
* And needs some optimization.
*
*
* 重要!!!
* このサンプルはローカルのセキュリティ関連の問題により、
* コンテキストでしか動きません。今のところ、ソースコード
* をダウンロードしてローカルのマシンで見てもらうしか
* ありません。
*
* どうすれば、この手の問題を回避出来るのでしょう?
*
* そして、最適化も必要ですね。
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.Loader;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.system.SecurityDomain;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.ByteArray;
[SWF(frameRate=12,width=465,height=465)]
public class FlashTest extends Sprite {
private var loader:Loader;
private var player:*;
private var bitmapData:BitmapData;
private var textField:TextField;
private var unitW:int;
private var unitH:int;
private var row:int;
private var column:int;
private static const palette:String = "@#$%&8BMW*mwqpdbkhaoQ0OZXYUJCLtfjzxnuvcr[]{}1()|/?Il!i><+_~-;,. ";
private var sh:int;
private var sw:int;
private var lastTime:int;
private var bitmapWidth:int;
private var bitmapHeight:int;
private var size:int = 8;
public function FlashTest() {
//Security.allowDomain('*');
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//sw = stage.stageWidth;
//sh = stage.stageHeight;
sw = sh = 465;
x = sw >> 1;
y = sh >> 1;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, loadInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
//addChild(loader);
}
private function loadInit(event:Event):void {
player = loader.content;
player.addEventListener("onReady", playerReady);
player.x = -x;
player.y = -y;
//var ldr:Loader = new Loader;
//ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function ():void {
//player = ldr.content;
//player.addEventListener("onReady", playerReady);
//player.x = -x;
//player.y = -y;
//loader.content["cueVideoById"]("6T_bYZc-Tv0",0,"hd720");
//loader.content["playVideo"]();
//});
//ldr.loadBytes(loader.contentLoaderInfo.bytes);
}
private function playerReady(event:Event):void {
player.setSize(sw, sh);
player.cueVideoById("6T_bYZc-Tv0",0,"hd720");
player.playVideo();
bitmapData = new BitmapData(sw >> 3, sh >> 3);
bitmapWidth = bitmapData.width;
bitmapHeight = bitmapData.height;
textField = new TextField;
textField.text = 'A\nAA';
textField.setTextFormat(new TextFormat('_typewriter', size));
var rect:Rectangle = textField.getCharBoundaries(3);
unitW = rect.x;
unitH = rect.y;
column = sw / unitW + 1;
row = sh / unitH + 1;
textField.text = '';
textField.width = sw;
textField.height = sh;
textField.x = -sw >> 1;
textField.y = -sh >> 1;
textField.multiline = true;
textField.mouseEnabled = false;
addChild(textField);
addEventListener(Event.ENTER_FRAME, update);
}
private function update(e:Event):void
{
bitmapData.draw(player, new Matrix(1 / 8, 0, 0, 1 / 8));
var htmlText:String = '<font face="_typewriter" size="'+size+'">';
var col:uint;
var r:int;
var g:int;
var b:int;
var index:int;
var pix:ByteArray = bitmapData.getPixels(bitmapData.rect);
for (var j:int = 0; j < row; ++j)
{
for (var i:int = 0; i < column; ++i)
{
index = (((unitW * i) >> 3) + bitmapWidth * ((unitH * j) >> 3)) << 2;
r = pix[1+index];
g = pix[2+index];
b = pix[3+index];
col = (r << 16) | (g << 8) | b;
htmlText += '<font color="#' + (col.toString(16)) + '">' + palette.charAt(63 - (r + g + b) / 3 / 4) + '</font>';
}
htmlText += '\n';
}
textField.htmlText = htmlText + '</font>';
}
}
}