创建视频播放器,由于某种原因找不到rtmp流。我必须遗漏一些明显的东西,但似乎无法找到原因。我正在测试的流是rtmp://cp67126.edgefcs.net/ondemand/mediapm/osmf/content/test/akamai_10_year_f8_512K,肯定在那里。
package
{
import com.bfwpub.data.*;
import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
public class BFW_VideoPlayer extends Sprite
{
private static const PLAYER_CONFIG:String = "data/player_config.xml";
private var _video:Video;
private var _playerData:PlayerData;
private var _videoData:VideoData;
private var _controlbarData:ControlBarData;
private var _videoPath:String;
private var _debugTxt:TextField;
// net connection object for net stream
private var _ncConnection:NetConnection;
// net stream object
private var _nsStream:NetStream;
public function BFW_VideoPlayer()
{
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, loadConfig);
xmlLoader.load(new URLRequest(PLAYER_CONFIG));
}
private function loadConfig(e:Event):void
{
var config:XML = new XML(e.target.data);
//store data in Objects
_playerData = new PlayerData();
_videoData = new VideoData();
_controlbarData = new ControlBarData();
//populate PlayerData
_playerData.autoPlay = config.@autoPlay;
_playerData.autoRewind = config.@autoRewind;
_playerData.smoothing = config.@smoothing;
_playerData.height = config.@height;
_playerData.isLive = config.@isLive;
_playerData.scaleMode = config.@scaleMode;
_playerData.width = config.@width;
//populate VideoData
_videoData.deliveryType = config.mediaElement.deliveryType;
_videoData.file = config.mediaElement.file;
_videoData.mediaPath = config.mediaElement.mediaPath;
_videoData.streamType = config.mediaElement.streamType;
_videoData.buffer = config.mediaElement.buffer;
//populate ControlBarData
_controlbarData.autoHide = config.controlBar.autoHide;
_controlbarData.captionPath = config.controlBar.captionPath;
_controlbarData.fullScreen = config.controlBar.fullScreen;
_controlbarData.skinPath = config.controlBar.skinPath;
//_videoPath = "rtmp://"+_videoData.mediaPath+_videoData.file;
_videoPath = "rtmp://cp67126.edgefcs.net/ondemand/mediapm/osmf/content/test/akamai_10_year_f8_512K"
createPlayer();
}
private function createPlayer():void
{
_debugTxt = new TextField();
_debugTxt.width = 200;
_debugTxt.height = 200;
this.addChild(_debugTxt);
_video = new Video();
_video.height = _playerData.height;
_video.width = _playerData.width;
this.addChild(_video);
createConnection();
}
private function createConnection():void
{
// create a new net connection, add event listener and connect
// to null because we don’t have a media server
_ncConnection = new NetConnection();
_ncConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_ncConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
_ncConnection.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
_ncConnection.addEventListener(AsyncErrorEvent.ASYNC_ERROR,metaHandler);
_ncConnection.connect(null);
}
/** Catch security errors. **/
private function errorHandler(evt:ErrorEvent):void {
trace("[ErrorEvent]"+evt.text)
};
/** Catch noncritical errors. **/
private function metaHandler(evt:ErrorEvent):void {
trace("[ErrorEvent]"+evt.text)
};
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
public function netStatusHandler(event:NetStatusEvent):void
{
trace("["+event.info.code+"]");
_debugTxt.text += "["+event.info.code+"]\n";
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + _videoPath);
break;
}
}
private function connectStream():void {
_nsStream = new NetStream(_ncConnection);
_nsStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_nsStream.bufferTime = _videoData.buffer;
_nsStream.client = new Client();
_video.attachNetStream(_nsStream);
_video.smoothing = _playerData.smoothing;
_nsStream.play(_videoPath);
}
}
import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
public class BFW_VideoPlayer extends Sprite
{
private static const PLAYER_CONFIG:String = "data/player_config.xml";
private var _video:Video;
private var _playerData:PlayerData;
private var _videoData:VideoData;
private var _controlbarData:ControlBarData;
private var _videoPath:String;
private var _debugTxt:TextField;
// net connection object for net stream
private var _ncConnection:NetConnection;
// net stream object
private var _nsStream:NetStream;
public function BFW_VideoPlayer()
{
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, loadConfig);
xmlLoader.load(new URLRequest(PLAYER_CONFIG));
}
private function loadConfig(e:Event):void
{
var config:XML = new XML(e.target.data);
//store data in Objects
_playerData = new PlayerData();
_videoData = new VideoData();
_controlbarData = new ControlBarData();
//populate PlayerData
_playerData.autoPlay = config.@autoPlay;
_playerData.autoRewind = config.@autoRewind;
_playerData.smoothing = config.@smoothing;
_playerData.height = config.@height;
_playerData.isLive = config.@isLive;
_playerData.scaleMode = config.@scaleMode;
_playerData.width = config.@width;
//populate VideoData
_videoData.deliveryType = config.mediaElement.deliveryType;
_videoData.file = config.mediaElement.file;
_videoData.mediaPath = config.mediaElement.mediaPath;
_videoData.streamType = config.mediaElement.streamType;
_videoData.buffer = config.mediaElement.buffer;
//populate ControlBarData
_controlbarData.autoHide = config.controlBar.autoHide;
_controlbarData.captionPath = config.controlBar.captionPath;
_controlbarData.fullScreen = config.controlBar.fullScreen;
_controlbarData.skinPath = config.controlBar.skinPath;
//_videoPath = "rtmp://"+_videoData.mediaPath+_videoData.file;
_videoPath = "rtmp://cp67126.edgefcs.net/ondemand/mediapm/osmf/content/test/akamai_10_year_f8_512K"
createPlayer();
}
private function createPlayer():void
{
_debugTxt = new TextField();
_debugTxt.width = 200;
_debugTxt.height = 200;
this.addChild(_debugTxt);
_video = new Video();
_video.height = _playerData.height;
_video.width = _playerData.width;
this.addChild(_video);
createConnection();
}
private function createConnection():void
{
// create a new net connection, add event listener and connect
// to null because we don’t have a media server
_ncConnection = new NetConnection();
_ncConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_ncConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
_ncConnection.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
_ncConnection.addEventListener(AsyncErrorEvent.ASYNC_ERROR,metaHandler);
_ncConnection.connect(null);
}
/** Catch security errors. **/
private function errorHandler(evt:ErrorEvent):void {
trace("[ErrorEvent]"+evt.text)
};
/** Catch noncritical errors. **/
private function metaHandler(evt:ErrorEvent):void {
trace("[ErrorEvent]"+evt.text)
};
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
public function netStatusHandler(event:NetStatusEvent):void
{
trace("["+event.info.code+"]");
_debugTxt.text += "["+event.info.code+"]\n";
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + _videoPath);
break;
}
}
private function connectStream():void {
_nsStream = new NetStream(_ncConnection);
_nsStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_nsStream.bufferTime = _videoData.buffer;
_nsStream.client = new Client();
_video.attachNetStream(_nsStream);
_video.smoothing = _playerData.smoothing;
_nsStream.play(_videoPath);
}
}
答案 0 :(得分:4)
使用rtmp,连接有点不同。试试这个:
_ncConnection.connect("rtmp://cp67126.edgefcs.net/ondemand/mediapm/osmf/content/test");
_nsStream.play("akamai_10_year_f8_512K");