JS实现DIV提示框的效果
作者:lingye 日期:2007-01-08
防刷新的音乐插件
作者:lingye 日期:2008-10-17
练习js中类的写法而写的东西
效果如页面右侧
JavaScript代码
- document.writeln('<div id="lymusicbox" style="width:90%;margin:0 auto;text-align:center"></div>')
- //音乐类
- function MusicInfo(){}
- MusicInfo.prototype={
- title:"Unknown Music",
- author:"Unknown",
- url:"",
- id:0
- }
- //播放器信息类
- function PlayerInfo(){}
- PlayerInfo.prototype={
- //播放状态,1=停止,2=暂停,3=播放,6=正在缓冲,9=正在连接,10=准备就绪
- playState:"",
- //当前进度,字符串格式。如“00:23”
- currentPositionString:"",
- //音量0-100
- volume:80,
- //媒体总长度,字符串格式。如“03:24”
- mediaDurationString:""
- }
- //主体类
- MusicPlayer = function() {
- var playerobj=null;
- var playerstr='';
- var musiclist=new Array();
- //尝试连接秒数
- var waitseconds=0;
- //停止播放秒数
- var stopseconds=0;
- //是否手动停止
- var stopclick=false;
- return {
- //public
- errmsg:"",
- israndom:true,
- parentwindow:null,
- status:"stop",
- musicinfo:new MusicInfo(),
- playerinfo:new PlayerInfo(),
- init: function() {
- //加载列表
- this.LoadMusicList();
- //随机挑选一首歌
- if(this.israndom){
- var r_id=Math.round(Math.random()*musiclist.length);
- this.musicinfo=musiclist[r_id];
- }
- else{
- this.musicinfo=musiclist[0];
- }
- if(this.errmsg!=""){$id("lymusicbox").innerHTML=this.errmsg;return;}
- //获取父窗体,如果页面在框架中则取顶层窗体
- if(window.parent!=window.top){this.parentwindow=window.top;}
- else{this.parentwindow=window.parent;}
- if(this.parentwindow==window.self){return;}
- if(this.parentwindow.musicframe==null){
- var iframe=this.parentwindow.document.createElement("iframe");
- iframe.width="100%";
- iframe.height="0px";
- iframe.name="musicframe",
- iframe.id="musicframe",
- iframe.frameBorder="0";
- iframe.scrolling="no";
- iframe.src="about:blank";
- this.parentwindow.document.body.appendChild(iframe);
- if(navigatorname=="Firefox"){playerstr='<div id="currentmusicid">'+this.musicinfo.id+'</div><object id="m_player" type="application/x-mplayer2" width="99%" data="'+this.musicinfo.url+'"></object>';}
- else{
- playerstr='<div id="currentmusicid">'+this.musicinfo.id+'</div><object id="m_player" type="application/x-oleobject" height="64" width="99%" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">';
- playerstr+='<param value="'+this.musicinfo.url+'" name="url" />';
- playerstr+='</object>';
- }
- this.parentwindow.musicframe.document.writeln(playerstr);
- this.parentwindow.musicframe.document.close();
- }
- else{
- var currentmusicid=this.parentwindow.musicframe.document.getElementById("currentmusicid").innerHTML;
- this.musicinfo=musiclist[Math.round(currentmusicid)];
- }
- playerobj=this.parentwindow.musicframe.document.getElementById("m_player");
- this.status="play";
- //添加控制面板
- var plathtml='';
- plathtml+='<b id="music_status"></b><br/>\r\n';
- plathtml+=' <a href="javascript:MusicPlayer.Stop()">停止</a>';
- plathtml+=' <a href="javascript:MusicPlayer.Play()">播放</a>';
- plathtml+=' <a href="javascript:MusicPlayer.Pause()">暂停</a>';
- plathtml+=' <a href="javascript:MusicPlayer.Pre()">上一首</a>';
- plathtml+=' <a href="javascript:MusicPlayer.Next()">下一首</a><br/>';
- plathtml+=' <span id="music_t"></span>\r\n';
- plathtml+=' <a href="javascript:window.top.location.replace(this.location.href)">静音版</a>\r\n';
- $id("lymusicbox").innerHTML=plathtml;
- },
- Stop:function(){
- if(navigatorname!="Firefox"){playerobj.controls.stop();}
- else{this.parentwindow.musicframe.document.body.innerHTML="";}
- this.status="stop";
- stopclick=true;
- },
- Play:function(){
- if(this.status=="stop" || this.status=="pause"){
- if(navigatorname!="Firefox"){playerobj.controls.play();}
- else{this.parentwindow.musicframe.document.writeln(playerstr);this.parentwindow.musicframe.document.close();}
- this.status="play";
- }
- },
- ChangePlay:function(){
- if(navigatorname!="Firefox"){playerobj.controls.stop();playerobj.url=this.musicinfo.url;playerobj.controls.play();}
- else{
- playerstr='<div id="currentmusicid">'+this.musicinfo.id+'</div><object id="m_player" type="application/x-mplayer2" width="99%" data="'+this.musicinfo.url+'"></object>';
- this.parentwindow.musicframe.document.writeln(playerstr);
- this.parentwindow.musicframe.document.close();
- }
- this.status="play";
- },
- Pause:function(){
- if(this.status=="play"){
- if(navigatorname!="Firefox"){playerobj.controls.pause();}
- else{}
- this.status="pause";
- }
- },
- GoTo:function(id){
- if(Math.round(id)<0){id=musiclist.length-1;}
- else if(Math.round(id)>musiclist.length-1){id=0;}
- this.musicinfo=musiclist[id];
- this.ChangePlay();
- this.parentwindow.musicframe.document.getElementById("currentmusicid").innerHTML=id;
- },
- Next:function(){
- var nowid=this.musicinfo.id;
- this.GoTo(nowid+1);
- },
- Pre:function(){
- var nowid=this.musicinfo.id;
- this.GoTo(nowid-1);
- },
- RefreshStatus:function(){
- if(navigatorname!="Firefox"){
- switch(playerobj.playState){
- case 1:
- if(stopseconds>6 && stopclick==false){
- if(this.israndom){this.GoTo(Math.round(Math.random()*musiclist.length));}
- else{this.Next();}
- }
- this.playerinfo.playState="已停止";
- this.status="stop";
- stopseconds+=1;
- break;
- case 2:
- this.playerinfo.playState="已暂停";
- this.status="pause";
- break;
- case 3:
- this.playerinfo.playState=this.musicinfo.title+"-"+this.musicinfo.author;
- this.status="play";
- waitseconds=0;
- stopseconds=0;
- stopclick=false;
- break;
- case 6:
- this.playerinfo.playState="正在缓冲";
- break;
- case 9:
- if(waitseconds>15){
- if(this.israndom){this.GoTo(Math.round(Math.random()*musiclist.length));}
- else{this.Next();}
- }
- this.playerinfo.playState="正在连接";
- waitseconds+=1;
- break;
- case 10:
- if(stopseconds>5){
- if(this.israndom){this.GoTo(Math.round(Math.random()*musiclist.length));}
- else{this.Next();}
- }
- this.playerinfo.playState="准备就绪";
- this.status="stop";
- stopseconds+=1;
- break;
- }
- this.playerinfo.currentPositionString=playerobj.controls.currentPositionString;
- this.playerinfo.volume=playerobj.controls.volume;
- this.playerinfo.mediaDurationString=playerobj.currentMedia.durationString;
- var n_t=Math.round(playerobj.controls.currentPositionString.replace(":",""));
- var t_t=Math.round(playerobj.currentMedia.durationString.replace(":",""));
- if((t_t-n_t<=5) && (n_t!=0) ){
- if(this.israndom){
- this.GoTo(Math.round(Math.random()*musiclist.length));
- }
- else{this.Next();}
- }
- }
- $id("music_status").innerHTML=this.playerinfo.playState;
- $id("music_t").innerHTML=this.playerinfo.currentPositionString+"/"+this.playerinfo.mediaDurationString;
- },
- //加载音乐列表
- LoadMusicList:function(){
- try{
- var xmlobj=GetXMLContent(installpath+musiclistfile);
- var musiclistobj=xmlobj.selectNodes("//musiclist/music");
- var list_len=musiclistobj.length;
- if(list_len==0) this.errmsg="未成功加载音乐列表!";
- var musicinfo_t;
- for(var m_i=0;m_i<list_len;m_i++){
- musicinfo_t=new MusicInfo();
- musicinfo_t.title=musiclistobj[m_i].selectSingleNode("title/text()").nodeValue;
- musicinfo_t.author=musiclistobj[m_i].selectSingleNode("author/text()").nodeValue;
- musicinfo_t.url=musiclistobj[m_i].selectSingleNode("url/text()").nodeValue;
- musicinfo_t.id=m_i;
- musiclist.push(musicinfo_t);
- }
- }
- catch(e){
- this.errmsg="未成功加载音乐列表!";
- }
- }
- };
- }();
- function updatemusicstatus(){
- if(MusicPlayer.errmsg!=""){$id("lymusicbox").innerHTML=MusicPlayer.errmsg;return;}
- MusicPlayer.RefreshStatus();
- $id("music_status").innerHTML=MusicPlayer.playerinfo.playState;
- $id("music_t").innerHTML=MusicPlayer.playerinfo.currentPositionString+"/"+MusicPlayer.playerinfo.mediaDurationString;
- }
- function loadfun(){
- MusicPlayer.init();
- window.setInterval(updatemusicstatus,1000);
- }
- if(window.parent!=window.self){
- if(document.all){window.document.body.onload=loadfun}
- else{window.addEventListener("load",loadfun,false);}
- }
- else{
- $id("lymusicbox").innerHTML='<a href="index.htm">音乐版</a>';
- }
晋江文学网小偷
作者:lingye 日期:2008-09-26
C# 检测图像中出现次数最多的颜色
作者:lingye 日期:2008-06-09
C# 检测图像中出现次数最多的颜色
http://www.lingye.net/lingye_net/Demo/ImageCore/ImageColor.aspx
核心:
C#代码
- BitmapData srcData = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
- unsafe
- {
- byte* p = (byte*)srcData.Scan0.ToPointer();
- for (int y = 0; y < h; y++)
- {
- for (int x = 0; x < w; x++)
- {
- string colorkey = ColorTranslator.ToHtml(Color.FromArgb(p[2], p[1], p[0]));
- ......
- p += 3;
- }
- p += srcData.Stride - w * 3;
- }
- }
Tags: c# 颜色 BitmapData









