Question
video class cannot work in flex, how?
i am a flex beginner, try to use flex 2.0 to develop flv
player, but it seem i cannot work. pls help me see what error
inside the code.
--------------------------------------------------------------------VideoExample.as------------------------------------------------------------
package {
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 = "a.flv";
private var connection:NetConnection;
private var stream:NetStream;
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
//
public function VideoExample() {
trace("videoExample");
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect('rtmp://localhost/sample_room/_definst_');
trace("connect");
}
private function netStatusHandler(event:NetStatusEvent):void {
trace(event.info.code);
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.
}
}
}
--------------------------------------------------------------------VideoExample.as------------------------------------------------------------
package {
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 = "a.flv";
private var connection:NetConnection;
private var stream:NetStream;
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
//
public function VideoExample() {
trace("videoExample");
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect('rtmp://localhost/sample_room/_definst_');
trace("connect");
}
private function netStatusHandler(event:NetStatusEvent):void {
trace(event.info.code);
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.
}
}
}