Archives
在 PHPChina 的论坛看到有人问,如何使用 PHP 得到一个媒体的文件的播放时间,然后就自己尝试用 COM 写了一段代码,开始以为蛮复杂的,不过还好思路对了,只是在浩瀚的 MSDN 上查找 WMP SDK 的资料折腾的够呛,最后写出的代码却只有寥寥几行,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php // mp3, wav or any other file formats that media player supports. $file = "C:/I Wanna Go To A Place.mp3"; if (!file_exists($file)) { exit('Media file does not exist.'); } // Create an instance of Windows Media Player $player = new COM("WMPlayer.OCX"); $media = $player->newMedia($file); // Get the duration of a media file (seconds) print $media->duration; |
在 PHP Manual 的 XV. COM and .Net (Windows) 一章,还看到一位叫 Pedro 的同学提交的利用 WMP OCX 弹出光驱的 PHP 代码。
有兴趣的朋友可以玩玩:
1 2 3 4 5 6 | <?php // Create an instance of Windows Media Player $mp = new COM("WMPlayer.OCX"); // Ejects the first cd-rom on the drive list $mp->cdromcollection->item(0)->eject(); |
Comments Off
Aug 7th, 2007 | Filed under PHP
Tags: PHP