|
Mr Margaret Scratcher, Sr. Member
Posted: 15 September 2011 04:14 AM Total Posts: 344
... I’m finding that the only way to get it to update is like this, whcih is called every frame:
private function updateTV():void { TVBMD = new flash.display.BitmapData (256,256) TVBMD.draw (TVmc) //TVmat.updateTexture; TVmat = new BitmapMaterial(TVBMD) //TVmat.updateTexture; TVplane.material = TVmat; }
Which results in an error due to, I guess, filling up the graphics memory with a new ‘TVmat’ every frame.. TVmat.updatetexture *should*, if I understand correctly, have a look at the TVBMD and rewrite that as the texture, but it dosn’t seem to work…
Also, I have to create a new TVBMD bitmap and draw the movie clip into it each frame, or else I don’t get the updated version drawn, I’d have though that each time I call the draw function it would draw over the current contents with whatever is currently in TVmc?
It is very cool though, playing a youtube video on a plane.. Once I get this bit nailed it should be easy enough to turn it into a class.
|
Alejandro Santander, Administrator
Posted: 15 September 2011 04:57 PM Total Posts: 414
[ # 1 ]
Hey,
I’ve made a little test and it seems to work fine for me: http://www.lidev.com.ar/tests/away3d/movie_material/
I am not creating a new material on enterframe though, just this:
bitmapData.perlinNoise(50, 50, 2, 1000 * Math.random(), false, true, 7, true); BitmapMaterial(cube.material).bitmapData = bitmapData; BitmapMaterial(cube.material).updateTexture();
|
Mr Margaret Scratcher, Sr. Member
Posted: 15 September 2011 05:09 PM Total Posts: 344
[ # 2 ]
Aha, that’s it! I just wasn’t calling the updateTexture properly..
private function updateTV():void { TVBMD.draw (TVmc) BitmapMaterial(TVplane.material).updateTexture(); }
SIMPLE!
Thankyou!
|
Mr Margaret Scratcher, Sr. Member
Posted: 15 September 2011 06:32 PM Total Posts: 344
[ # 3 ]
Hmmm…. Working locally, but the security sandbox rears its ugly head online…
adding
Security.allowDomain("s.ytimg.com"); Security.allowInsecureDomain("*"); Security.allowDomain("*")
allows me to play the youtube video in the moveiclip, but then running the updateTV function throws up an error..
|
Alejandro Santander, Administrator
Posted: 15 September 2011 10:04 PM Total Posts: 414
[ # 4 ]
Well, that is a question for Adobe, not us!
Usually I just set -use-network=false on my compiler options for testing locally.
|
Darcey, Moderator
Posted: 15 September 2011 10:10 PM Total Posts: 209
[ # 5 ]
Try placing the “crossdomain.xml” file at the root.
crossdomain.xml
<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="all" /> <allow-access-from domain="*" /> <allow-http-request-headers-from domain="*" headers="*"/> </cross-domain-policy>
Try add you tube to it and see if it helps.
I get the compiler in Flex / Flash Builder play up with me often with sandboxing… Often can be fixed by a simple restart… And it often only happens when I run the html file direct on compile, but then it doesn’t online or local server.
|
|
Mr Margaret Scratcher, Sr. Member
Posted: 15 September 2011 10:26 PM Total Posts: 344
[ # 7 ]
Odd, removed
Security.allowDomain("http://s.ytimg.com"); Security.allowInsecureDomain("*"); Security.allowDomain("*")
from my code, and removed the crossdomain.xml, and still no problems at all in loading the youtube player into a movieclip and adding it to the view, but trying to update the bitmapdata from that movieclip is not happening…
|
Darcey, Moderator
Posted: 15 September 2011 10:30 PM Total Posts: 209
[ # 8 ]
Try:
1. Add loaded SWF to stage, check it works…
2. If point 1 works, take a BitmapData.draw of the moviclip and test
3. If point 2 works, take the bitmap data to bitmap, and test
4. If point 3 works, add the bitmap to the stage and see if the result is correct
5. If point 4 works, I don’t see why BitmapMaterial cant be updated in the enter_frame from the BitmapData.draw of the loaded SWF
It may reveal something…. Doing this process….
|
Darcey, Moderator
Posted: 15 September 2011 10:30 PM Total Posts: 209
[ # 9 ]
Oh and run each step online to make sure…
|
Mr Margaret Scratcher, Sr. Member
Posted: 15 September 2011 10:42 PM Total Posts: 344
[ # 10 ]
When you say
“Add the loaded swf to stage” are you talking about the movie clip which contains the loaded youtube player?
Full TV bits:
private function addTV():void { trace("adding TV") TVplane = new Plane(TVmat, 100, 90) TVplane.x =-600 TVplane.z = - 110 - 50 TVplane.y = 205 - 45 TVplane.rotationY = -90 view.scene.addChild (TVplane) loadTV(); function loadTV():void { //Security.allowDomain("http://s.ytimg.com"); //Security.allowInsecureDomain("*"); //Security.allowDomain("*") trace ("loading TV Video") VideoID = "QHSsYY82tZw" TVLoader = new Loader(); var loaderContext:LoaderContext = new LoaderContext (); loaderContext.checkPolicyFile = true; TVLoader.contentLoaderInfo.addEventListener(Event.INIT, loadTVTrailerComplete, false, 0, true); TVLoader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"), loaderContext);// Chromeless player //TVLoader.load(new URLRequest("http://www.youtube.com/v/" + VideoID + "?version=3")); //chrome player } } private function loadTVTrailerComplete(e:Event):void { TVPlayer = TVLoader.content TVPlayer.addEventListener("onReady", onTVPlayerReady, false, 0, true); var TVScreen:MovieClip = new MovieClip TVScreen.addChild(DisplayObject(TVPlayer)); TVmc.addChild (TVScreen) addChild(TVmc); //offset screen TVScreen.x = 15 TVScreen.y = 13 TVLoader.contentLoaderInfo.removeEventListener(Event.INIT, loadTVTrailerComplete); TVLoader = null; } private function onTVPlayerReady(event : Event) : void { TVPlayer.removeEventListener("onReady", onTVPlayerReady); TVPlayer.addEventListener("onStateChange", TVPlayerStateChange);
// Once this event has been dispatched by the player, we can use // cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl // to load a particular YouTube video. TVPlayer.loadVideoById(VideoID); TVPlayer.setSize(222, 125); TVPlayer.mute();
} private function TVPlayerStateChange(event : Event) : void { trace ("TV PLAYER STATE CHANGED") } private function updateTV():void { //Security.allowDomain("http://s.ytimg.com"); //Security.allowInsecureDomain("*"); //Security.allowDomain("*") TVBMD.draw (TVmc) BitmapMaterial(TVplane.material).updateTexture(); }
I can load the youtube player using the above code, which then adds the content of the loader to a movie clip, which is in turn added to another movieclip. I can add this final movieclip to the stage and it plays as expected.
It’s just when I try to draw that movieclip into another bitmap.
Are you suggesting to draw it to one bitmap, then bounce that to another one and use that for the texture?
|
Darcey, Moderator
Posted: 15 September 2011 11:02 PM Total Posts: 209
[ # 11 ]
Cooked up a test app here with some of your code and some new stuff running the tests I mentioned…. As soon as bitmapData.draw is called sandox error… lol
Running a few more tests and will get back 2 u..
|
Mr Margaret Scratcher, Sr. Member
Posted: 15 September 2011 11:19 PM Total Posts: 344
[ # 12 ]
Nope..
If I can paste this:
TVBMD.draw(TVmc); var bMap:Bitmap = new Bitmap (TVBMD); addChild(bMap) //BitmapMaterial(TVplane.material).updateTexture();
after
TVLoader = null;
Then it throws the error…
I do have this in the output:
Warning: Domain s2.youtube.com does not explicitly specify a meta-policy, but Content-Type of policy file http://s2.youtube.com/crossdomain.xml is ‘text/x-cross-domain-policy’. Applying meta-policy ‘by-content-type’.
|
Darcey, Moderator
Posted: 15 September 2011 11:25 PM Total Posts: 209
[ # 13 ]
I’ve cooked up an AS3 app in FB4 which is using a youtube video.
1. I add it to the stage… All fine.
2. I declare and set bitmap and bitmap data variables… All fine
3. If attempt
bmpData.draw(TVLoader.content);
Results in Sandbox error (online and on local server)
4. If attempt
bmpData.draw(stage,null,null,null,new Rectangle(0,0,240,120),false);
Results in Sandbox error (online and on local server)
There appears to be various hacks dating back to 2007 where bytearrays are used etc to pass a loader to another loader (for images to bytearray) but none of this appears to work in 10.3
I think your out of luck on this 1, try the api’s on youtube, there’s probably something there that requires a developer account and id to be registered to use content loading their security policy passed by the approved developer id in the generated swf. (at a guess).. Else download the flv and stick it on your server…
package { // ------------------------------------------------------------------------------------------------------------------------------------------------ import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Loader; import flash.display.LoaderInfo; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.geom.Rectangle; import flash.net.URLRequest; import flash.system.LoaderContext; import flash.system.Security; import flash.text.TextField; import flash.text.TextFieldAutoSize;
// ------------------------------------------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------------------------------------------ [SWF(frameRate="31")] // ------------------------------------------------------------------------------------------------------------------------------------------------ public class Test extends Sprite { // ------------------------------------------------------------------------------------------------------------------------------------------------ //http://www.youtube.com/watch?v=fBp4iy6D9Os private var VideoID:String = "fBp4iy6D9Os"; private var TVLoader:Loader; // ------------------------------------------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------------------------------------------ public function Test() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; Security.allowDomain("www.youtube.com"); Security.allowDomain("http://s.ytimg.com"); //Security.allowDomain("http://s.ytimg.com"); //Security.allowInsecureDomain("*"); //Security.allowDomain("*") trace ("loading TV Video") TVLoader = new Loader(); bmpData = new BitmapData(240,120); bmpData.draw(stage,null,null,null,new Rectangle(0,0,240,120),false); //bmp = new Bitmap(bmpData); var loaderContext:LoaderContext = new LoaderContext(); loaderContext.checkPolicyFile = true; TVLoader.contentLoaderInfo.addEventListener(Event.INIT, loadTVTrailerComplete, false, 0, true); TVLoader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"), loaderContext);// Chromeless player //TVLoader.load(new URLRequest("http://www.youtube.com/v/" + VideoID + "?version=3")); //chrome player } // ------------------------------------------------------------------------------------------------------------------------------------------------ private var youTubeVideoObject:Object; // ------------------------------------------------------------------------------------------------------------------------------------------------ private function loadTVTrailerComplete(e:Event):void { addChild(TVLoader); //trace(TVLoader.content); var txt:TextField = new TextField(); txt.autoSize = TextFieldAutoSize.LEFT; txt.text = TVLoader.content.toString(); txt.x = 5; txt.y = 300; addChild(txt); youTubeVideoObject = TVLoader.content; youTubeVideoObject.addEventListener("onReady", youTubeVideoObjectReadyHandler); } // ------------------------------------------------------------------------------------------------------------------------------------------------ private var bmp:Bitmap; private var bmpData:BitmapData; // ------------------------------------------------------------------------------------------------------------------------------------------------ private function youTubeVideoObjectReadyHandler(e:Event):void { youTubeVideoObject.setSize(240,120); youTubeVideoObject.loadVideoById(VideoID, 0); bmpData = new BitmapData(240,120); // These are standard AS3 commands and methods which are blocked, so your going to have to hack this before you can pass the bitmap data to // Away3D //bmpData.draw(stage,null,null,null,new Rectangle(0,0,240,120),false); //bmp = new Bitmap(bmpData); } // ------------------------------------------------------------------------------------------------------------------------------------------------ } }
|
Darcey, Moderator
Posted: 15 September 2011 11:28 PM Total Posts: 209
[ # 14 ]
Encase your reading after I done an update.. Reload and see last function code comments for what I am on about.
|
Mr Margaret Scratcher, Sr. Member
Posted: 15 September 2011 11:44 PM Total Posts: 344
[ # 15 ]
Hmmmmm… Very frustrating… Looks great running here locally…
I did try this before with papervision, lemme dig out the code and see if there was anything in there…
|