百度首页 | 百度空间
 
查看文章
 
iPlayer
2007-11-15 14:25
//iPlayer , Copyright (c) 2006-2007 Changlong, <http://music.ad.xwall.cn>, MIT Style License.
// r1028
var Browser = Client;
var iPlayer = new Class({
   
    State:99,

    Implements: [Options, Events],

    options: {
        height: 1 ,
        width: 1 ,
        properties: {},
        params: {
            enableContextMenu:-1,
            defaultframe: 'iPlayerWin',   
            ShowControls: 0,
            showdisplay: -1,    MovieWindowSize:-1,
            showstatusbar:0,
            balance:0,    volume:70,
            AutoSize:0
        },
        events: {}
    } ,

    initialize: function(options){
        this.setOptions(options || {} );
        iPlayer.instances[iPlayer.UID]    = this;
        this.id    = iPlayer.UID++;
        this.options.properties    = $extend(
            {height: this.options.height, width: this.options.width, id:'iPlayer' + iPlayer.UID++}, this.options.properties);
        if (Browser.Engine.trident){
            this.options.properties.classid = 'CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6';
        }
        if( Browser.Engine.gecko ){
            this.options.properties.type="application/x-ms-wmp";
        }
        this.build();
    },
   
    build: function(){
        var shtml    = '<object ';
        for(var i in this.options.properties) shtml += ' ' + i + '=\'' + this.options.properties[i] + '\'';
        shtml += '>';
        for (var i in this.options.params) shtml += '<param name=\'' + i + '\' value=\'' + this.options.params[i] + '\' />' ;
        shtml += '</object>';
        if( Browser.Engine.gecko ){
            this.addEvent('onChange', this.onChange );
            shtml += '<script event=\'playStateChange(ns)\' for=\''+ this.options.properties.id + '\'+>iPlayer.StateChange('+this.id+', ns)<\/script>';
        }
        this.dom    = $(new Element('div',{
                styles:{    width:1,height:1, overflow:'hidden', position:'absolute', top: 1, left:1 }       
            }).setHTML(shtml).inject(document.body).firstChild);
        if(Browser.Engine.trident){
            window[this.options.properties.id].attachEvent("PlayStateChange", this.onChange.bind(this) );
        }
        // Controls ClosedCaption Error ErrorItem Media Network Player Playlist Settings
    },
   
    play: function(url){
        if( url) this.dom.URL    = url;
        this.dom.controls.play();
    },
   
    pause: function(url){
        this.dom.controls.pause();
    },

    stop: function(url){
        this.dom.controls.stop();
    },

    get: function(){
        return {
                'pos': Math.ceil(this.dom.controls ? this.dom.controls.currentPosition * 1000: 0 ),
                'len': Math.ceil(this.dom.currentMedia ? this.dom.currentMedia.duration*1000 : 0),
                'Pos': this.dom.controls ? (this.dom.controls.currentPositionString || '00:00') : '00:00',
                'Len': this.dom.currentMedia ? this.dom.currentMedia.durationString : '00:00',
                'vol': this.dom.settings ? this.dom.settings.volume : 50,
                'buf': this.dom.network? this.dom.network.bufferingProgress :0,
                'down': this.dom.network? this.dom.network.downloadProgress: 0
            };
    },
   
    set: function(key, val){
        try{
        switch (key) {
            case 'pos':   
                this.dom.controls.currentPosition = val/1000;
            break;
            case 'vol':   
                this.dom.settings.volume = val ;
            break;
            default: ;
        }
        } catch(err){}
    },
   
    onChange: function(ns){
        if( this.State    == ns ){
            return false;
        }
        var    os    = this.State;
        this.State    = ns;
        if(Browser.Engine.trident){
            this.fireEvent("onChange", ns);
        }
        switch (ns) {
            case 1:   
                this.fireEvent("onStop", [ns, os] );
            break;
            case 2:   
                this.fireEvent("onPause", [ns, os] );
            break;
            case 3:   
                this.fireEvent("onPlay", [ns, os] );
            break;
            case 4:
                this.fireEvent("onWaiting", [ns, os] );
            break;
            case 6:   
                this.fireEvent("onBuffer", [ns, os] );
            break;
            case 8:
                this.fireEvent("onEnd", [ns, os] );
            break;
            case 10:   
                this.fireEvent("onDestroy", [ns, os] );
            break;
            case 99:   
                this.fireEvent("onReady", [ns, os] );
            break;
            default:
                //document.title    = (ns +' from ' + os);
            break;
        }
    }

});

iPlayer.UID    = 0;
iPlayer.instances    = [];
iPlayer.StateChange    = function(id, ns ){
    iPlayer.instances[id].fireEvent("onChange", ns);
}

类别:Web | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码:
 

     

©2008 Baidu