·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3取FMS流媒体服务器播放器mp3的问题

时间:2013-10-20 15:19cuplayer
[AS3]as3取FMS流媒体服务器播放器mp3的问题,草民在做一个播放器,从网上找了个代码,但是有问题,就是读取mp4格式的时候没问题,但读mp3格式的,取不到mp3的总长度。代码如下,各位大大有空的时候来指点指点。

草民在做一个播放器,从网上找了个代码,但是有问题,就是读取mp4格式的时候没问题,但读mp3格式的,取不到mp3的总长度。代码如下,各位大大有空的时候来指点指点。

  1. package { 
  2.         import flash.display.Sprite; 
  3.         import flash.events.NetStatusEvent; 
  4.         import flash.events.SecurityErrorEvent; 
  5.         import flash.media.Video; 
  6.         import flash.net.NetConnection; 
  7.         import flash.net.NetStream; 
  8.         import flash.events.Event; 
  9.         import flash.net.ObjectEncoding; 
  10.  
  11.         public class Main142 extends Sprite { 
  12.                 private var videoURL:String="mp4:1"
  13.                 private var nc:NetConnection; 
  14.                 private var ns:NetStream; 
  15.  
  16.                 public function Main142() { 
  17.                         nc = new NetConnection(); 
  18.                         nc.objectEncoding=ObjectEncoding.AMF0; 
  19.                         nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 
  20.                         nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 
  21.                         nc.connect("rtmp://localhost/vod/media"); 
  22.                         nc.client=this
  23.                 } 
  24.                 private function netStatusHandler(event:NetStatusEvent):void { 
  25.                         trace("netStatusHandler= " + event.info.code); 
  26.                         switch (event.info.code) { 
  27.                                 case "NetConnection.Connect.Success" : 
  28.                                         connectStream(); 
  29.                                         break; 
  30.                                 case "NetStream.Play.StreamNotFound" : 
  31.                                         trace("Stream not found: " + videoURL); 
  32.                                         break; 
  33.                         } 
  34.                 } 
  35.                 private function securityErrorHandler(event:SecurityErrorEvent):void { 
  36.                         trace("securityErrorHandler: " + event); 
  37.                 } 
  38.                 private function connectStream():void { 
  39.                         ns=new NetStream(nc); 
  40.                         ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 
  41.                         var client:Object=new Object(); 
  42.                         client.onMetaData=onMetaData; 
  43.                         ns.client=client; 
  44.                         var video:Video = new Video(); 
  45.                         video.attachNetStream(ns); 
  46.                         ns.play(videoURL); 
  47.                         addChild(video); 
  48.                 } 
  49.                 public function onBWDone():void { 
  50.                 } 
  51.                 public function onMetaData(info:Object):void { 
  52.                         trace("CuPlayer.com提示总时间:"+info.duration); 
  53.                 } 
  54.         } 

 终于搞定了,在这里保存下,省的以后找不到了,虽然是抄的别人的。
Application.onConnect=function(client)
{
     Application.acceptConnection(client);
}
Client.prototype.getMediaLength=function (mp3_name)
{
     return Stream.length(mp3_name);
}

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器