Created
March 15, 2013 16:32
-
-
Save IQAndreas/5171164 to your computer and use it in GitHub Desktop.
See: http://www.gotoandlearn.com/play.php?id=114
Loads the video in at runtime rather than from a SWC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
import com.transmote.flar.FLARManager; | |
import com.transmote.flar.marker.FLARMarker; | |
import com.transmote.flar.marker.FLARMarkerEvent; | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.media.Video; | |
import org.libspark.flartoolkit.support.pv3d.FLARCamera3D; | |
import org.papervision3d.objects.primitives.Plane; | |
import org.papervision3d.render.LazyRenderEngine; | |
import org.papervision3d.scenes.Scene3D; | |
import org.papervision3d.view.Viewport3D; | |
[SWF(width='640', height='480', backgroundColor='#000000', frameRate='40')] | |
public class Playvideo extends Sprite | |
{ | |
private var fm:FLARManager; | |
private var scene:Scene3D | |
private var view:Viewport3D; | |
private var view:FLARCamera3D; | |
private var lre:LazyRenderEngine; | |
private var p:Plane; | |
private var marker:FLARMarker; | |
// Video loading | |
private var video:Video; | |
private var connection:NetConnection; | |
private var stream:NetStream; | |
public function Playvideo() | |
{ | |
initFLAR(); | |
initVideo("externalVideo.flv"); // <-- Change the filename here! | |
} | |
private function initVideo(videoName:String):void | |
{ | |
video = new Video(320, 480); // Size will be changed later | |
addChild(video); | |
connection = new NetConnection(); | |
connection.connect(null); | |
stream = new NetStream(connection); | |
stream.client = {onMetaData: metadataHandler}; | |
video.attachNetStream(stream); | |
// Load the video | |
stream.play(videoName); | |
// Don't play the video immediately | |
stopVideo(); | |
} | |
private function stopVideo():void | |
{ | |
stream.pause(); | |
stream.seek(0); | |
} | |
private function playVideo():void | |
{ | |
stream.resume(); | |
} | |
private function pauseVideo():void | |
{ | |
stream.pause(); | |
} | |
private function metadataHandler(metadataObj:Object):void | |
{ | |
video.width = metadataObj.width; | |
video.height = metadataObj.height; | |
} | |
private function initFLAR():void | |
{ | |
fm = new FLARManager("flarConfig.xml"); | |
fm.addEventListener(FLARMarkerEvent.MARKER_ADDED, onAdded); | |
fm.addEventListener(FLARMarkerEvent.MARKER_REMOVED, onRemoved); | |
fm.addEventListener(EVENT.INIT, init3D); | |
addChild(Sprite(fm.flarSource)); | |
} | |
private function onAdded(e:FLARMarkerEvent):void | |
{ | |
marker=e.marker; | |
playVideo(); | |
} | |
private function onRemoved(e:FLARMarkerEvent):void | |
{ | |
marker=null; | |
stopVideo(); | |
// If you prefer, you can pause the video rather than reset it to the beginning | |
//pauseVideo(); | |
} | |
private function init3D(e:Event):void | |
{ | |
scene= new Scene3D(); | |
camera= new FLARCamera3D(fm.cameraParams); | |
camera.z=-30; | |
view= new Viewport3D(640, 480, true); | |
lre= new LazyRenderEngine(Scene, camera, view); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment