Flash Media Server 视频流如何放到网页上播放?
发布网友
发布时间:2022-05-12 19:11
我来回答
共1个回答
热心网友
时间:2023-10-19 04:06
package book{
import flash.display.Sprite;
import flash.events.*;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class VideoExample extends Sprite {
private var videoURL:String = "test.flv";//这里就是你的flv地址。
private var connection:NetConnection;
private var stream:NetStream;
public function VideoExample() {
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" :
trace("success!!!");
connectStream();
break;
case "NetStream.Play.StreamNotFound" :
trace("Unable to locate video: " + videoURL);
break;
}
}
private function connectStream():void {
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var video:Video = new Video(550,400);
video.attachNetStream(stream);
video.name = "video"
video.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
stream.play(videoURL);
addChild(video);
}
private function enterFrameHandler(event:Event):void
{
trace(event.target.name);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function asyncErrorHandler(event:AsyncErrorEvent):void {
// ignore AsyncErrorEvent events.
}
}
}
帧上
import book.VideoExample;
addChild(new VideoExample());
上面的东西,是很久前做测试写的一个类。就是播放一个外部的视频流吧。你可以用上面的东西做成一个swf,然后再放到网页上面去。