一个可能对你有用的垃圾东东
因为朋友机是公司的垃圾机10G,98M内存,所以帮他做了个自动查找播放东东,
有兴趣的朋友可以瞧下
实现办法:
人工添加歌曲信息(歌曲名称或及歌手)做成列表,随机选择一个,打开网页查找可用的链接并进行播放
功能:
加歌曲:可复制网上的歌曲排行的列表格式成可用的列表或自己一行一个歌曲办法添加列表;
重复播放,
显示歌词
指定忍耐上限(找到可用链接到播放时间长,超过,更换快的)
可双击选择播放
暂时这么多,
其它的功能改进可以自己考虑添加
----------------
主文件:自动网上搜索播放音乐程序.hta(因为要跨域操作,必须用HTA)
------------------
<html APPLICATION=yes><HEAD>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>自动网上搜索播放音乐程序</title>
<HTA:APPLICATION ID="autoplayer"
APPLICATIONNAME="autoplayer"
ICON="图标.ico"
NAVIGABLE="yes"
SINGLEINSTANCE="yes"
></HTA:APPLICATION>
</head>
<script language ='javascript'>
<!--
var current = 0; //指示当前使用的列表变量
var listindex0 = -1; //列表变量0;
var listindex1 = -1; //列表变量1
var urlindex0 = 0; //列表0的使用链接下标
var urlindex1 = 0; //列表1的使用链接下标
var stop2nexttimer; //防止短时的停止事件频繁调用下首函数
var buffertimer; //等待时间
var playtimer; //播放定时器
function window.onload()
{
if( isNaN ( listwin.document.body.buffertime * 1 ) )
listwin.document.body.buffertime = 30 ; //当缓冲时间未声明或非数字时,设置为默认值
buffertime.value = listwin.document.body.buffertime; //读取缓冲时间
setlistwin();
setlistindex( current ); //开始播放处理
}
function setlistwin()
{
listwindiv.style.height = document.body.clientHeight - listwindiv.offsetTop;
if( showtxt.checked )
txtdiv.style.height = listwindiv.style.height;
}
window.onresize = setlistwin;
function setlistindex( which )
{
if( which == current )document.title = "请稍等!正在处理!";
if ( eval( "listindex" + which ) < 0 )
{ //变量未有可用值
if ( ( eval( "listindex" + which + " = getlistindex()" ) ) < 0 ) return -1; //列表变量得到的是不可用值时,停止
}
if ( listwin.document.all[ eval( "listindex" + which ) ].url == null || listwin.document.all[ eval( "listindex" + which ) ].url == "" )
{//列表变量值对象未有URL
eval( "urlindex" + which + " = 0" ); //未有URL,必须查找,先置URL指示变量为零
if( eval( "searchwin" + which ).location == "http://d.sogou.com/music?class=1&query=" + escape( listwin.document.all[ eval( "listindex" + which ) ].innerText ) )
{//已打开,直接查找即可
selecturl( which );
}else
{//未打开查找网页
eval( "searchwin" + which ).location = "http://d.sogou.com/music?class=1&query=" + escape( listwin.document.all[ eval( "listindex" + which ) ].innerText ); //打开查找网页,等待loaded状态事件
}
}else if( which == current )
{
playurl( which ); //已有URL,直接调用播放
setlistindex ( ( !which ) * 1 ); //准备后备列表
}
}
function changeurl()
{
listwin.document.all[ eval( "listindex" + current ) ].url = ""; //出错的地址不能要
setlistindex( current );
}
function playurl( which )
{
if ( player.url == listwin.document.all[ eval( "listindex" + current ) ].url )
{ //不是当前使用的的,而是准备列表不能播放
return -1;
}
player.url = listwin.document.all[ eval( "listindex" + current ) ].url; //设置播放器的地址为当前的列表的URL
clearTimeout( playtimer );
playtimer = setTimeout( "player.controls.play()" ,500 );
document.title = "歌曲: " + listwin.document.all[ eval( "listindex" + which ) ].innerText + " => " + listwin.document.all[ eval( "listindex" + which ) ].url; //在标题栏显示当前的歌曲信息
clearTimeout( buffertimer );
buffertimer = setTimeout( "selecturl( current )", buffertime.value * 1000 ); //设置等待时间
if( showtxt.checked ) play2showtxt(); //决定是否查找歌词
}
function getlistindex()
{
if( listwin.document.getElementsByTagName( "A" ).length < 1 )
{
alert( "\t出错!\n \n可能是列表框中不存在任何列表! \n\n请检查后添加歌曲再试!" );
return -1; //返回不存在的值
}
return listwin.document.getElementsByTagName( "A" )[ Math.ceil( listwin.document.getElementsByTagName( "A" ).length * Math.random() ) - 1 ].sourceIndex; //返回随机选择的列表下标
}
function selecturl( which )
{
if( which == current && eval( "searchwin" + which ).location.href.indexOf( "http://" ) > -1)document.title = "请稍等!正在处理!";
if( ( eval( "listindex" + which ) < 0 ) || ( eval( "searchwin" + which ).location.href.indexOf( "http://" ) < 0 ) ) return -1; //未完全载入,不能读取链接
var allurl = eval( "searchwin" + which ).document.links;
for( ; eval( "urlindex" + which ) < allurl.length; eval( "urlindex" + which + "++") )
{ //从上次搜索的下标处开始
if( allurl[ eval( "urlindex" + which ) ].href.match( /(\.mp3 *$)|(\.wma *$)/gi ) != null)
{ //只有是MP3或WMA文件的链接才要
if( allurl[ eval( "urlindex" + which ) ].href.match( /^ *http\:\/\/220\.181\.26\.88.+/gim ) != null )
{ //是搜狗的还要在后面加上?WXC
listwin.document.all[ eval( "listindex" + which ) ].url = allurl[ eval( "urlindex" + which ) ].href + "?wxc";
}else
{
listwin.document.all[ eval( "listindex" + which ) ].url = allurl[ eval( "urlindex" + which ) ].href; //普通的链接直接设置就行了,
}
if( ( listwin.document.all[ eval( "listindex" + which ) ].url == player.url ) && ( which == current ) )
{
listwin.document.all[ eval( "listindex" + which ) ].url = ""; //出错的地址不能要
continue;
}
eval( "urlindex" + which + "++" ); //为下次再查找时指示到下一个
if( which == current )
{
setlistindex ( ( !which ) * 1 ); // 处理准备列表:
return playurl( which ); //找到不必再执行找不到的指令
}else { return 1; }
}
}
listwin.document.all[ eval( "listindex" + which ) ].url = ""; //找不到了,移除URL属性
if( which == current )
{ //是当前的,所以假设后备的列表已准备好,直接调用它,而把当前的换成后备的,
nextlist();
}else{//不是当前的,所以直接重设就行了,
eval( "listindex" + which + " = -1" );//把此变量设为-1,以可以重新操作,
setlistindex( which ); //找不到了,重设;
}
}
function nextlist( )
{//下一首
eval( "listindex" + current + " = -1" ); //把此变量设为-1,以可以重新操作,
setlistindex ( ( current = ( !current ) * 1 ) ); // 处理准备列表:
}
function play2showtxt()
{
if( txtwin.location != "http://d.sogou.com/gecisearch.so?class=5&query=" + escape( listwin.document.all[ eval( "listindex" + current ) ].innerText ) )
txtwin.location = "http://d.sogou.com/gecisearch.so?class=5&query=" + escape( listwin.document.all[ eval( "listindex" + current ) ].innerText ); //查找歌词
}