|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
非常拉跨的一段代码,见笑了。
- function DEF_CUEOBJ(){
- this.performer="";
- this.songwriter="";
- this.title="";
- this.file="";
- this.fileType="";
- this.rem=[];
- this.track=[];
- }
- DEF_CUEOBJ.prototype={
- setCommand:{
- /**
- * @param {Array<String>} _cl 指令的字符串数组
- */
- rem:function(_cl){
- this.rem.push(_cl);
- },
- file:function(_cl){
- this.file=_cl[1];
- this.fileType=_cl[2];
- },
- title:function(_cl){
- this.title=_cl[1];
- },
- performer:function(_cl){
- this.performer=_cl[1];
- },
- songwriter:function(){
- this.songwriter=_cl[1];
- },
- // track
- // 因为js的继承反射内容是复制这个对象的引用,所以即使是在子类追加也会追加到基类上,非常拉跨。 所以我把子类的反射的内容写在基类上了...
-
- index:function(_cl){
- var indexNub=parseInt(_cl[1]);
- var time=cue_timeToSecond(_cl[2]);
- var lastTrack;
- if(this.root.track.length-2>=0){
- lastTrack=this.root.track[this.root.track.length-2];
- }
- switch(indexNub){
- case 1:
- this.op=time;
- if(lastTrack&&(lastTrack.ed==undefined)){
- lastTrack.ed=time;
- }
- break;
- case 0:
- lastTrack.ed=time;
- break;
- default:
- this.indexList.push(time);
- break;
- }
- }
- }
- }
- function DEF_CUEOBJTrack(file,root,trackIndex){
- this.performer="";
- this.songwriter="";
- this.title="";
- this.ListIndex;
- this.rem=[];
- this.trackIndex=trackIndex;
- this.root=root;
- this.file=file;
- this.op; //秒
- this.ed;
- this.indexList=[];
- }
- inheritClass(DEF_CUEOBJ,DEF_CUEOBJTrack);
- DEF_CUEOBJTrack.prototype.getDuration=function(){
- return this.ed-this.op;
- }
- /**
- * 把cue的表示时间的格式转换成秒
- * @param {String} timeStr mm:ss:ff
- * @returns {Number}
- */
- function cue_timeToSecond(timeStr){
- var temp=timeStr.split(':');
-
- return parseInt(temp[0])*60+parseInt(temp[1])+parseInt(temp[2])/75;
- }
- function loadCue(str){
- var p=0,q=0,isQuotes=false;
- var tempStr;
- var rtn=new DEF_CUEOBJ();
- var then=rtn;
- var CommandList=[];
- for(;p<str.length;++p){
- if(str[p]!=' '){
- for(q=p;(p<str.length);++p){
- if(str[p]=='"'){
- isQuotes=!isQuotes;
- if(isQuotes){
- q=p+1;
- }
- }
- if((str[p]==' ')&&(!isQuotes)){
- // 记录指令
- if(str[p-1]=='"'){
- tempStr=str.slice(q,p-1);
- }else{
- tempStr=str.slice(q,p);
- }
- CommandList.push(tempStr);
- q=p+1;
- }
- else if((str[p]=="\n")||(str[p]=="\r")){
- // 换行 进入下一条指令
- if(str[p-1]=='"'){
- tempStr=str.slice(q,p-1);
- }else{
- tempStr=str.slice(q,p);
- }
- CommandList.push(tempStr);
- if(CommandList[0].toLowerCase()=="track"){
- then=new DEF_CUEOBJTrack(rtn.file,rtn,rtn.track.length);
- rtn.track.push(then);
- }
- else{
- if(then.setCommand[CommandList[0].toLowerCase()]){
- then.setCommand[CommandList[0].toLowerCase()].call(then,CommandList);
- }
- else{
- // 不支持这个指令
- }
- }
- do{ ++p; } while((str[p+1]=="\n")||(str[p+1]=="\r"));
- CommandList=[];
- break;
- }
- }
- }
- }
- return rtn;
- }
复制代码
就是把cue的指令的格式转换成json而已。
挺菜的。 |
|