For some reason I cannot find the answer via either google or flashkit. For a schoolproject we're using wirecast to stream media. However when I run in it in the browser the Client asks me to allow the url to load: http://tinypic.com/r/34ebvwo/7
How can I bypass it? This is my ('ugly') code:
Code:
package {
import com.greensock.TweenMax;
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.TimerEvent;
import flash.media.Video;
import flash.net.*;
import flash.utils.Timer;
public class Flashstream extends Sprite
{
private var server:String = "rtmp://avans.flashstreaming.eu/live/";
private var stream:String = "myStream";
private var nc:NetConnection = null;
private var nsPlay:NetStream;
private var bufferTime:Number = 3;
public var videoObj:Video;
private var controls:MovieClip;
private var play:MovieClip = new playButton();
private var pause:MovieClip = new pauseButton();
private var fs:MovieClip = new fsButton();
private var window:MovieClip = new wButton();
private var fsActive:Boolean = false;
private var mouseActive:Timer;
public function Flashstream()
{
createButtons();
connectPlayer();
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, onResize);
onResize(new Event(Event.RESIZE));
}
private function onResize(event:Event):void
{
var r:Number = 3 / 4;
var width:Number = stage.stageWidth;
var height:Number = stage.stageHeight;
if((width * r) > stage.stageHeight)
{
r = 4 / 3;
videoObj.height = height;
videoObj.width = height * r;
} else {
videoObj.height = width * r;
videoObj.width = width;
}
videoObj.x = (stage.stageWidth - videoObj.width) / 2;
videoObj.y = (stage.stageHeight - videoObj.height) / 2;
controls.y = stage.stageHeight - controls.height - 10;
controls.x = (stage.stageWidth - controls.width) / 2;
}
private function createButtons():void
{
controls = new MovieClip();
controls.alpha = 0;
controls.addEventListener(MouseEvent.MOUSE_OVER, stopTimer);
controls.addEventListener(MouseEvent.MOUSE_OUT, startTimer);
addChild(controls);
TweenMax.to(controls, 0.5, {alpha:1});
play.buttonMode = true;
play.visible = true;
play.name = "play";
play.addEventListener(MouseEvent.CLICK, buttonClick);
controls.addChild(play);
pause.buttonMode = true;
pause.visible = false;
pause.name = "pause";
pause.addEventListener(MouseEvent.CLICK, buttonClick);
controls.addChild(pause);
fs.buttonMode = true;
fs.visible = true;
fs.name = "fs";
fs.addEventListener(MouseEvent.CLICK, buttonClick);
fs.x = fs.width + 8;
controls.addChild(fs);
window.buttonMode = true;
window.visible = false;
window.name = "window";
window.addEventListener(MouseEvent.CLICK, buttonClick);
window.x = window.width + 8;
controls.addChild(window);
mouseActive = new Timer(2000, 1);
mouseActive.addEventListener(TimerEvent.TIMER_COMPLETE, toggleBar);
mouseActive.start();
stage.addEventListener(MouseEvent.MOUSE_MOVE, toggleBar);
}
private function startTimer(event:MouseEvent):void
{
mouseActive = new Timer(2000, 1);
mouseActive.addEventListener(TimerEvent.TIMER_COMPLETE, toggleBar);
mouseActive.start();
}
private function stopTimer(event:MouseEvent):void
{
mouseActive.stop();
mouseActive = null;
}
private function toggleBar(event:Event):void
{
if(controls.alpha == 1)
TweenMax.to(controls, 0.5, {alpha:0});
else {
TweenMax.to(controls, 0.5, {alpha:1});
if(mouseActive) mouseActive.start();
}
}
private function buttonClick(event:MouseEvent):void
{
switch(event.target.name)
{
case "play":
connectPlayer();
break;
case "pause":
disconnectPlayer();
break;
case "fs":
toggleFullScreen();
break;
case "window":
toggleFullScreen();
break;
}
}
private function toggleFullScreen():void
{
if(stage.displayState == StageDisplayState.NORMAL) {
stage.displayState = StageDisplayState.FULL_SCREEN;
window.visible = true;
fs.visible = false;
} else {
stage.displayState = StageDisplayState.NORMAL;
window.visible = false;
fs.visible = true;
}
onResize(new Event(Event.RESIZE));
}
private function connectPlayer():void
{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);
nc.connect(server);
}
private function disconnectPlayer():void
{
videoObj.visible = false;
play.visible = true;
pause.visible = false;
nsPlay.close();
nsPlay = null;
nc.close();
nc = null;
}
private function ncOnStatus(event:NetStatusEvent):void
{
var code:String = event.info.code;
if(code == "NetConnection.Connect.Success")
playStream();
else if (code == "NetConnection.Connect.Failed" || code == "NetConnection.Connect.Rejected")
trace("connection failed");
}
private function playStream():void
{
nsPlay = new NetStream(nc);
nsPlay.addEventListener(NetStatusEvent.NET_STATUS, nsOnStatus);
var nsPlayClientObj:Object = new Object();
nsPlay.client = nsPlayClientObj;
nsPlay.bufferTime = bufferTime;
nsPlay.play(stream);
videoObj.attachNetStream(nsPlay);
}
private function nsOnStatus(event:NetStatusEvent):void
{
var code:String = event.info.code;
if(code == "NetStream.Play.Start")
init();
else if (code == "NetStream.Play.StreamNotFound" || code == "NetStream.Play.Failed")
trace("stream failed");
}
private function init():void
{
videoObj.visible = true;
play.visible = false;
window.visible = false;
pause.visible = true;
fs.visible = true;
}
}
}