Flash 使用NetConnection类
我正在尝试使用NetConnection类连接到外部服务器上的实时视频源。我已将其设置为在用户单击播放按钮时开始播放我的视频,但是,每次单击播放按钮时,我的输出中都会显示: ArgumentError:错误#2126:必须连接NetConnection对象。 在flash.net::NetStream/ctor()上 在flash.net::NetStream()上 在Over/connectLiveStream()上[Over::frame2:31] 你知道为什么这不起作用吗?以下是(我认为相关的)代码:Flash 使用NetConnection类,flash,actionscript-3,Flash,Actionscript 3,我正在尝试使用NetConnection类连接到外部服务器上的实时视频源。我已将其设置为在用户单击播放按钮时开始播放我的视频,但是,每次单击播放按钮时,我的输出中都会显示: ArgumentError:错误#2126:必须连接NetConnection对象。 在flash.net::NetStream/ctor()上 在flash.net::NetStream()上 在Over/connectLiveStream()上[Over::frame2:31] 你知道为什么这不起作用吗?以下是(我认为相
提前感谢。我正在从adobe文档网站复制以下内容:
package {
import flash.display.Sprite;
import flash.events.*;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class NetStatusEventExample extends Sprite {
private var videoURL:String = "Video.flv";
private var connection:NetConnection;
private var stream:NetStream;
public function NetStatusEventExample() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(null);
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video: " + videoURL);
break;
}
}
private function connectStream():void {
var stream:NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var video:Video = new Video();
video.attachNetStream(stream);
stream.play(videoURL);
addChild(video);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function asyncErrorHandler(event:AsyncErrorEvent):void {
// ignore AsyncErrorEvent events.
}
}
}
class CustomClient {
public function onMetaData(info:Object):void {
trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void {
trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}
希望这能有所帮助,如果出现安全错误,您也需要在连接的流媒体服务器上设置跨域策略文件
链接:
nc
对象添加一些事件处理程序,以查看NetStatusEvent
的运行情况。您可以在此处给出connection.connect()参数的示例吗?在您的代码中,您正在传递null。我想知道是否唯一允许的协议是rtmp协议?我希望不是因为我希望服务器是GlassFish(java)服务器。。。
package {
import flash.display.Sprite;
import flash.events.*;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class NetStatusEventExample extends Sprite {
private var videoURL:String = "Video.flv";
private var connection:NetConnection;
private var stream:NetStream;
public function NetStatusEventExample() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(null);
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video: " + videoURL);
break;
}
}
private function connectStream():void {
var stream:NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var video:Video = new Video();
video.attachNetStream(stream);
stream.play(videoURL);
addChild(video);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function asyncErrorHandler(event:AsyncErrorEvent):void {
// ignore AsyncErrorEvent events.
}
}
}
class CustomClient {
public function onMetaData(info:Object):void {
trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void {
trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}