[AS3]flv视频播放器NetStream.play播放时遇到的问题(源代码示例)
代码中 play flv 格式的文件.没问题.
为何 play mp3 格式的时候. 就找不到了呢? 根目录存在 b.mp3 文件
错误提示是 Stream not found: b
- package
- {
- import flash.display.Sprite;
- import flash.display.Stage;
- import flash.media.Sound;
- import flash.media.Microphone;
- import flash.media.SoundChannel;
- import flash.media.SoundTransform;
- import flash.media.SoundLoaderContext;
- import flash.net.*;
- import flash.events.*;
- public class rtmpPlayer extends Sprite
- {
- private var _sound:Sound;
- private var _netNc:NetConnection = new NetConnection();
- private var _ns:NetStream;
- private var nsClient:CustomClient = new CustomClient();
- private var soundXForm:SoundTransform = new SoundTransform();
- public function rtmpPlayer() {
- soundXForm.volume = 0.5;
- _netNc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus);
- _netNc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
- _netNc.connect(null);
- //CuPLayer.com:addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
- }
- private function onNetStatus(event:NetStatusEvent=null):void {
- //CuPLayer.com:handles NetConnection and NetStream status events
- switch (event.info.code) {
- case "NetConnection.Connect.Success":
- //play stream if connection successful
- connectStream();
- trace("NetConnection.Connect.Success");
- break;
- case "NetStream.Play.StreamNotFound":
- //error if stream file not found in
- //CuPLayer.com:location specified
- trace("Stream not found: " + _soundUrl);
- break;
- case "NetStream.Play.Stop":
- //do if video is stopped
- //CuPLayer.com:videoPlayComplete();
- trace("do if video is stopped");
- break;
- }
- //trace(event.info.code);
- }
- private function connectStream():void {
- _ns = new NetStream(_netNc);
- _ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR,doAsyncError);
- _ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
- _ns.client = nsClient;
- //_ns.play("b.flv");
- _ns.play("mp3:b");
- //_ns.soundTransform = soundXForm;
- }
- private function securityErrorHandler(event:SecurityErrorEvent):void {
- trace("securityErrorHandler: " + event);
- }
- private function asyncErrorHandler(event:AsyncErrorEvent):void {
- }
- private function onEnterFrameHandler(event:Event):void {
- //if(_ns) trace(_ns.bytesLoaded + "==" + _ns.bytesTotal);
- }
- public function doAsyncError (event:AsyncErrorEvent):void {
- trace("asyncErrorHandler: " + event.text);
- }
- }
- }
- class CustomClient {
- public function onPlayStatus( info:Object ):void{
- switch ( info.code ){
- case "NetStream.Play.Switch":
- break;
- case "NetStream.Play.Complete":
- trace("soundCompleteHandler");
- break;
- default:
- for ( var a:String in info ) {
- trace(a + " " + info[a]);
- }
- break;
- }
- }
- public function onCuePoint(info:Object):void {
- trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
- }
- public function onMetaData(info:Object):void {
- trace("metadata: duration=" + info.duration + " width=" + info.width +
" height=" + info.height + " framerate=" + info.framerate);- }
- }
Adobe AIR 和 Flash Player 9.0.115.0 和更高版本支持从标准 MPEG-4 容器格式中派生的文件。这些文件包括 F4V、MP4、M4A、MOV、MP4V、3GP 和 3G2(如果他们包含 H.264 视频和/或 HEAAC v2 编码音频)。与 Sorenson 或 On2 中相同的编码配置文件相比,H.264 可以在更低的位速率下交付更高品质的视频。AAC 是在 MPEG-4 视频标准中定义的一种标准音频格式。HE-AAC v2 是 AAC 的扩展,它使用频带复制 (SBR) 和参量立体声 (PS) 技术在低比特率下提高编码效率。
因为NetStream流不支持MP3格式的解码,把mp3文件转换成AAC,或者可以使用Sound类的URLRequest属性添加mp3文件。
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例