PHP编写一个mp3音乐播放器,基于DOS的播放器你用过吗?

截图:

首先使用array_rand函数,实现随机播放的功能。

要播放歌曲,还需要有一个播放器供PHP脚本使用,在这里使用一个命令行的方式执行媒体播放器MPXPLAY来播放音乐文件

PHP代码,搞个在线播放器:

<? while(true) { for($i=0;$i<5;$i++) { echo "/r/n"; } } echo "Ctrl+c退出播放状态/n"; sleep(5); $sheets=array(); $dir="e:/mp3"; $dh=opendir($dir) or die("不能打开音乐文件目录"); while(!(($file = readdir($dh))===false)) { if($file=="." || $file=="..") { continue; } if(eregi(".mp3|.wma",$file)) { $sheets[] .=$file; } } closedir($dh); $foo=$sheets[array_rand($sheets)]; echo "/n现在正在播放:$foo"; for($i=0;$i<3;$i++) { echo "/r/n"; } exec("D:/MPXP/MPXPLAY.exe d:/mp3/$foo"); for($i=0;$i<5;$i++) { echo "/r/n"; } ?>

你可能感兴趣的:(c,PHP,dos,File,脚本,音乐)