2016-10-13 00:16:48 点击量:13 标签: 收藏本文
草民在做一个播放器,从网上找了个代码,但是有问题,就是读取mp4格式的时候没问题,但读mp3格式的,取不到mp3的总长度。代码如下,各位大大有空的时候来指点指点。
- package {
- import flash.display.Sprite;
- import flash.events.NetStatusEvent;
- import flash.events.SecurityErrorEvent;
- import flash.media.Video;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.events.Event;
- import flash.net.ObjectEncoding;
- public class Main142 extends Sprite {
- private var videoURL:String="mp4:1";
- private var nc:NetConnection;
- private var ns:NetStream;
- public function Main142() {
- nc = new NetConnection();
- nc.objectEncoding=ObjectEncoding.AMF0;
- nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
- nc.connect("rtmp://localhost/vod/media");
- nc.client=this;
- }
- private function netStatusHandler(event:NetStatusEvent):void {
- trace("netStatusHandler= " + event.info.code);
- switch (event.info.code) {
- case "NetConnection.Connect.Success" :
- connectStream();
- break;
- case "NetStream.Play.StreamNotFound" :
- trace("Stream not found: " + videoURL);
- break;
- }
- }
- private function securityErrorHandler(event:SecurityErrorEvent):void {
- trace("securityErrorHandler: " + event);
- }
- private function connectStream():void {
- ns=new NetStream(nc);
- ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- var client:Object=new Object();
- client.onMetaData=onMetaData;
- ns.client=client;
- var video:Video = new Video();
- video.attachNetStream(ns);
- ns.play(videoURL);
- addChild(video);
- }
- public function onBWDone():void {
- }
- public function onMetaData(info:Object):void {
- trace("CuPlayer.com提示总时间:"+info.duration);
- }
- }
- }
终于搞定了,在这里保存下,省的以后找不到了,虽然是抄的别人的。
Application.onConnect=function(client)
{
Application.acceptConnection(client);
}
Client.prototype.getMediaLength=function (mp3_name)
{
return Stream.length(mp3_name);
}
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室