选择显示字体大小

一个解析mp3 id3 tag 和 mpeg 信息的类(来自zend.com),实际应用请看这里http://feifei2.bjedu.gov.cn...


   <?php
    /*
     * mp3 class
     *
     * rel. 0.1
     *
     * copyright (c) 2000 sumatra solutions srl    http://www.sumatrasolutions.com
     *                    ludovico magnocavallo    ludo@sumatrasolutions.com
     *
     * license type: gnu gpl http://www.gnu.org/copyleft/gpl.html
     *
     *    heavily inspired by
     *                    perl apache::mp3 module (l. stein) -- great module to create an apache-based mp3 server
     *                    perl mp3::info (c. nandor) -- very complicated, hard stuff but useful
     *                    java class de.vdheide.mp3 (j. vonderheide) -- great stuff, easy to read, had to debug synchronize() method
     *
     * id3v2 tags support not completed
     *
     * mp3 header reference at http://www.mp3-tech.org/
     *
     * // quick start:
     * &#36;mp3 = new mp3(&#36;myfilepath);
     * &#36;mp3->get_info();                    // file info in &#36;mp3->info array
     * &#36;mp3->get_id3();                    // id3 info in &#36;mp3->id3 array
     * &#36;mp3->send_pls(&#36;http_host)        // uses physical path to file in playlist url
     * &#36;mp3->stream()                        // streams file to browser
     *
     * &#36;id: mp3.php,v 1.10 2000/07/18 11:05:16 ludo exp &#36;
     *
     */  
    class mp3 {
        var &#36;id3_genres_array = array(
            &#39;blues&#39;, &#39;classic rock&#39;, &#39;country&#39;, &#39;dance&#39;, &#39;disco&#39;, &#39;funk&#39;, &#39;grunge&#39;, &#39;hip-hop&#39;, &#39;jazz&#39;, &#39;metal&#39;, &#39;new age&#39;, &#39;oldies&#39;, &#39;other&#39;, &#39;pop&#39;, &#39;r&b&#39;, &#39;rap&#39;, &#39;reggae&#39;, &#39;rock&#39;, &#39;techno&#39;, &#39;industrial&#39;,
            &#39;alternative&#39;, &#39;ska&#39;, &#39;death metal&#39;, &#39;pranks&#39;, &#39;soundtrack&#39;, &#39;euro-techno&#39;, &#39;ambient&#39;, &#39;trip-hop&#39;, &#39;vocal&#39;, &#39;jazz+funk&#39;, &#39;fusion&#39;, &#39;trance&#39;, &#39;classical&#39;, &#39;instrumental&#39;, &#39;acid&#39;, &#39;house&#39;,
            &#39;game&#39;, &#39;sound clip&#39;, &#39;gospel&#39;, &#39;noise&#39;, &#39;alternrock&#39;, &#39;bass&#39;, &#39;soul&#39;, &#39;punk&#39;, &#39;space&#39;, &#39;meditative&#39;, &#39;instrumental pop&#39;, &#39;instrumental rock&#39;, &#39;ethnic&#39;, &#39;gothic&#39;, &#39;darkwave&#39;,
            &#39;techno-industrial&#39;, &#39;electronic&#39;, &#39;pop-folk&#39;, &#39;eurodance&#39;, &#39;dream&#39;, &#39;southern rock&#39;, &#39;comedy&#39;, &#39;cult&#39;, &#39;gangsta&#39;, &#39;top 40&#39;, &#39;christian rap&#39;, &#39;pop/funk&#39;, &#39;jungle&#39;, &#39;native american&#39;, &#39;cabaret&#39;,
            &#39;new wave&#39;, &#39;psychadelic&#39;, &#39;rave&#39;, &#39;showtunes&#39;, &#39;trailer&#39;, &#39;lo-fi&#39;, &#39;tribal&#39;, &#39;acid punk&#39;, &#39;acid jazz&#39;, &#39;polka&#39;, &#39;retro&#39;, &#39;musical&#39;, &#39;rock & roll&#39;, &#39;hard rock&#39;, &#39;folk&#39;, &#39;folk/rock&#39;, &#39;national folk&#39;,
            &#39;swing&#39;, &#39;fast fusion&#39;, &#39;bebob&#39;, &#39;latin&#39;, &#39;revival&#39;, &#39;celtic&#39;, &#39;bluegrass&#39;, &#39;avantgarde&#39;, &#39;gothic rock&#39;, &#39;progressive rock&#39;, &#39;psychedelic rock&#39;, &#39;symphonic rock&#39;, &#39;slow rock&#39;, &#39;big band&#39;,
            &#39;chorus&#39;, &#39;easy listening&#39;, &#39;acoustic&#39;, &#39;humour&#39;, &#39;speech&#39;, &#39;chanson&#39;, &#39;opera&#39;, &#39;chamber music&#39;, &#39;sonata&#39;, &#39;symphony&#39;, &#39;booty bass&#39;, &#39;primus&#39;, &#39;porn groove&#39;, &#39;satire&#39;, &#39;slow jam&#39;, &#39;club&#39;, &#39;tango&#39;, &#39;samba&#39;,
            &#39;folklore&#39;, &#39;ballad&#39;, &#39;power ballad&#39;, &#39;rhythmic soul&#39;, &#39;freestyle&#39;, &#39;duet&#39;, &#39;punk rock&#39;, &#39;drum solo&#39;, &#39;acapella&#39;, &#39;euro-house&#39;, &#39;dance hall&#39;
        );
        var &#36;info_bitrates = array(
            1    =>    array(
                1    =>    array( 0 => 0, 16 => 32, 32 => 64, 48 => 96, 64 => 128, 80 => 160, 96 => 192, 112 => 224, 128 => 256, 144 => 288, 160 => 320, 176 => 352, 192 => 384, 208 => 416, 224 => 448, 240 => false),
                2    =>    array( 0 => 0, 16 => 32, 32 => 48, 48 => 56, 64 =>  64, 80 =>  80, 96 =>  96, 112 => 112, 128 => 128, 144 => 160, 160 => 192, 176 => 224, 192 => 256, 208 => 320, 224 => 384, 240 => false),
                3    =>    array( 0 => 0, 16 => 32, 32 => 40, 48 => 48, 64 =>  56, 80 =>  64, 96 =>  80, 112 =>  96, 128 => 112, 144 => 128, 160 => 160, 176 => 192, 192 => 224, 208 => 256, 224 => 320, 240 => false)
            ),
            2    =>    array(
                1    =>    array( 0 => 0, 16 => 32, 32 => 48, 48 => 56, 64 =>  64, 80 => 80, 96 => 96, 112 => 112, 128 => 128, 144 => 144, 160 => 160, 176 => 176, 192 => 192, 208 => 224, 224 => 256, 240 => false),
                2    =>    array( 0 => 0, 16 =>  8, 32 => 16, 48 => 24, 64 =>  32, 80 => 40, 96 => 48, 112 =>  56, 128 =>  64, 144 =>  80, 160 =>  96, 176 => 112, 192 => 128, 208 => 144, 224 => 160, 240 => false),
                3    =>    array( 0 => 0, 16 =>  8, 32 => 16, 48 => 24, 64 =>  32, 80 => 40, 96 => 48, 112 =>  56, 128 =>  64, 144 =>  80, 160 =>  96, 176 => 112, 192 => 128, 208 => 144, 224 => 160, 240 => false)
            ),
        );
        var &#36;info_versions = array(0 => &quot;reserved&quot;, 1 => &quot;mpeg version 1&quot;, 2 => &quot;mpeg version 2&quot;, 2.5 => &quot;mpeg version 2.5&quot;);
        var &#36;info_layers = array(&quot;reserved&quot;, &quot;layer i&quot;, &quot;layer ii&quot;, &quot;layer iii&quot;);
        var &#36;info_sampling_rates = array(
            0        =>    array(0 => false, 4 => false, 8 => false, 12 => false),
            1        =>    array(0 => &quot;44100 hz&quot;, 4 => &quot;48000 hz&quot;, 8 => &quot;32000 hz&quot;, 12 => false),
            2        =>    array(0 => &quot;22050 hz&quot;, 4 => &quot;24000 hz&quot;, 8 => &quot;16000 hz&quot;, 12 => false),
            2.5    =>    array(0 => &quot;11025 hz&quot;, 4 => &quot;12000 hz&quot;, 8 => &quot;8000 hz&quot;, 12 => false),
        );
        var &#36;info_channel_modes = array(0 => &quot;stereo&quot;, 64 => &quot;joint stereo&quot;, 128 => &quot;dual channel&quot;, 192 => &quot;single channel&quot;);
        var &#36;file = &quot;&quot;;
        var &#36;fh = false;
        var &#36;error = false;
        var &#36;id3_parsed = false;
        var &#36;id3 = array(
/*            &quot;tag&quot;            =>    &quot;&quot;,
            &quot;title&quot;        =>    &quot;unknown&quot;,
            &quot;author&quot;        =>    &quot;unknown&quot;,
            &quot;album&quot;        =>    &quot;unknown&quot;,
            &quot;year&quot;        =>    &quot;unknown&quot;,
            &quot;comment&quot;    =>    &quot;unknown&quot;,
            &quot;genre_id&quot;    =>    0,
            &quot;genre&quot;        =>    &quot;unknown&quot;
*/        );
        var &#36;url = &quot;&quot;;
        var &#36;info = array();
         
        function mp3(&#36;file, &#36;exitonerror=true) {
            if (file_exists(&#36;file)) {
                &#36;this->file = &#36;file;
                &#36;this->fh = fopen(&#36;this->file,&quot;r&quot;);
                global &#36;http_host, &#36;php_self;
                &#36;this->url = &quot;http://&#36;http_host/&#36;php_self&quot;;
            } else {
                &#36;this->error = &quot;no such file&quot;;
                if (&#36;exitonerror) &#36;this->exitonerror();
            }
        }
        function exitonerror() {
            echo(&#36;this->error);
            exit;
        }
        function set_id3(&#36;title = &quot;&quot;, &#36;author = &quot;&quot;, &#36;album = &quot;&quot;, &#36;year = &quot;&quot;, &#36;comment = &quot;&quot;, &#36;genre_id = 0) {
            &#36;this->error = false;
            &#36;this->wfh = fopen(&#36;this->file,&quot;a&quot;);
            fseek(&#36;this->wfh, -128, seek_end);
            fwrite(&#36;this->wfh, pack(&quot;a3a30a30a30a4a30c1&quot;, &quot;tag&quot;, &#36;title, &#36;author, &#36;album, &#36;year, &#36;comment, &#36;genre_id), 128);
            fclose(&#36;this->wfh);
        }
        function get_id3() {
            &#36;this->id3_parsed = true;
            fseek(&#36;this->fh, -128, seek_end);
            &#36;line = fread(&#36;this->fh, 10000);
            if (preg_match(&quot;/^tag/&quot;, &#36;line)) {
                &#36;this->id3 = unpack(&quot;a3tag/a30title/a30author/a30album/a4year/a30comment/c1genre_id&quot;, &#36;line);
                &#36;this->id3[&quot;genre&quot;] = &#36;this->id3_genres_array[&#36;this->id3][&quot;genre_id&quot;]];
                return(true);
            } else {
                &#36;this->error = &quot;no idv3 tag found&quot;;
                return(false);
            }
        }
        // get_info() helper methods
        function calculate_length(&#36;id3v2_tagsize = 0) {
          &#36;length = floor((&#36;this->info[&quot;filesize&quot;] - &#36;id3v2_tagsize) / &#36;this->info[&quot;bitrate&quot;] * 0.008);
            &#36;min = floor(&#36;length / 60);
            &#36;min = strlen(&#36;min) == 1 ? &quot;0&#36;min&quot; : &#36;min;
            &#36;sec = &#36;length % 60;
            &#36;sec = strlen(&#36;sec) == 1 ? &quot;0&#36;sec&quot; : &#36;sec;
            return(&quot;&#36;min:&#36;sec&quot;);
        }
        function get_info() {
//            &#36;this->get_id3v2header();
            &#36;second = &#36;this->synchronize();
//            echo(&quot;2nd byte = &#36;second <b>&quot; . decbin(&#36;second) . &quot;</b><br>&quot;);
            &#36;third = ord(fread(&#36;this->fh, 1));
            &#36;fourth = ord(fread(&#36;this->fh, 1));
            &#36;this->info[&quot;version_id&quot;] = (&#36;second & 16) > 0 ? ( (&#36;second & 8) > 0 ? 1 : 2 ) : ( (&#36;second & 8) > 0 ? 0 : 2.5 );
            &#36;this->info[&quot;version&quot;] = &#36;this->info_versions[ &#36;this->info][&quot;version_id&quot;] ];
            &#36;this->info[&quot;layer_id&quot;] = (&#36;second & 4) > 0 ? ( (&#36;second & 2) > 0 ? 1 : 2 ) : ( (&#36;second & 2) > 0 ? 3 : 0 );     ;
            &#36;this->info[&quot;layer&quot;] = &#36;this->info_layers[ &#36;this->info][&quot;layer_id&quot;] ];
            &#36;this->info[&quot;protection&quot;] = (&#36;second & 1) > 0 ? &quot;no crc&quot; : &quot;crc&quot;;
            &#36;this->info[&quot;bitrate&quot;] = &#36;this->info_bitrates[ &#36;this->info][&quot;version_id&quot;] ][ &#36;this->info][&quot;layer_id&quot;] ][ (&#36;third & 240) ];
            &#36;this->info[&quot;sampling_rate&quot;] = &#36;this->info_sampling_rates[ &#36;this->info][&quot;version_id&quot;] ][ (&#36;third & 12)];
            &#36;this->info[&quot;padding&quot;] = (&#36;third & 2) > 0 ? &quot;on&quot; : &quot;off&quot;;
            &#36;this->info[&quot;private&quot;] = (&#36;third & 1) > 0 ? &quot;on&quot; : &quot;off&quot;;
            &#36;this->info[&quot;channel_mode&quot;] = &#36;this->info_channel_modes[&#36;fourth & 192];
            &#36;this->info[&quot;copyright&quot;] = (&#36;fourth & 8) > 0 ? &quot;on&quot; : &quot;off&quot;;
            &#36;this->info[&quot;original&quot;] = (&#36;fourth & 4) > 0 ? &quot;on&quot; : &quot;off&quot;;
            &#36;this->info[&quot;filesize&quot;] = filesize(&#36;this->file);
            &#36;this->info[&quot;length&quot;] = &#36;this->calculate_length();
        }
        function synchronize() {
            &#36;finished = false;
            rewind(&#36;this->fh);
            while (!&#36;finished) {
                &#36;skip = ord(fread(&#36;this->fh, 1));
//                echo(&quot;inside synchronize() skip = &#36;skip <b>&quot; . decbin(&#36;skip) . &quot;</b><br>&quot;);
                while (&#36;skip != 255 && !feof(&#36;this->fh)) {
                    &#36;skip = ord(fread(&#36;this->fh, 1));
//                    echo(&quot;inside synchronize() skip = &#36;skip <b>&quot; . decbin(&#36;skip) . &quot;</b><br>&quot;);
                }
                if (feof(&#36;this->fh)) {
                    &#36;this->error(&quot;no info header found&quot;);
                    if (&#36;exitonerror) &#36;this->exitonerror();
                }
                &#36;store = ord(fread(&#36;this->fh, 1));
//                echo(&quot;inside synchronize() store = &#36;store <b>&quot; . decbin(&#36;store) . &quot;</b><br>&quot;);
                if (&#36;store >= 225) {
                    &#36;finished = true;
                } else if (feof(&#36;this->fh)) {
                    &#36;this->error(&quot;no info header found&quot;);
                    if (&#36;exitonerror) &#36;this->exitonerror();
                }
            }
            return(&#36;store);
        }
        function get_id3v2header() {
            &#36;bytes = fread(&#36;this->fh, 3);
            if (&#36;bytes != &quot;id3&quot;) {
                echo(&quot;no id3 tag&quot;);
                return(false);
            }
            // get major and minor versions
            &#36;major = fread(&#36;this->fh, 1);
            &#36;minor = fread(&#36;this->fh, 1);
            echo(&quot;id3v&#36;major.&#36;minor&quot;);
        }
        function stream() {
            if (!&#36;this->id3_parsed) {
                &#36;this->get_id3();
            }
            header(&quot;icy 200 ok\r\n&quot;);
            header(&quot;icy-notice1:this stream requires a shoutcast/icecast compatible player.<br>\r\n&quot;);
            header(&quot;icy-notice2:php mp3 class<br>\r\n&quot;);
            header(&quot;icy-name:&quot; . (count(&#36;this->id3) > 0 ? &#36;this->id3[&quot;title&quot;] . &quot; - &quot; . &#36;this->id3[&quot;author&quot;] . &quot; - &quot; . &#36;this->id3[&quot;album&quot;] . &quot; - &quot; . &#36;this->id3[&quot;year&quot;] : &#36;this->file) . &quot;\r\n&quot;);
            header(&quot;icy-genre:&quot; . (count(&#36;this->id3) > 0 ? &#36;this->id3[&quot;genre&quot;] : &quot;unspecified&quot;) . &quot;\r\n&quot;);
            header(&quot;icy-url:bbb\r\n&quot;);
            header(&quot;icy-pub:1\r\n&quot;);
            header(&quot;icy-br:320\r\n&quot;);
            rewind(&#36;this->fh);
            fpassthru(&#36;this->fh);
        }
        function send_playlist_header(&#36;numentries = 1) {
            header(&quot;content-type: audio/mpegurl;&quot;);
            echo(&quot;[playlist]\r\n\r\n&quot;);
            echo(&quot;numberofentries=&#36;numentries\r\n&quot;);
        }
        function send_pls(&#36;server) {
            &#36;this->send_playlist_header();
            &#36;path = &quot;/&quot;;
            &#36;path_array = explode(&quot;/&quot;, dirname(&#36;this->file));
            while(list(&#36;key,&#36;val) = each(&#36;path_array)) {
                &#36;path .= empty(&#36;val) ? &quot;&quot; : rawurlencode(&#36;val);
            }
            &#36;path .= &quot;/&quot;;
            &#36;file = rawurlencode(preg_replace(&quot;/\.mp3&#36;/&quot;, &quot;&quot;, basename(&#36;this->file)));
            echo(&quot;file1=http://&#36;server&#36;path&#36;file.mps\r\n&quot;);
        }
        function close() {
            @fclose(&#36;this->fh);
        }
    }

?>


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons