谷歌镜像 伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

PHP - Manual: SWFMovie::streamMP3

来源:网络转载 浏览:34138次 时间:2024-03-08
SWFMovie::writeExports » « SWFMovie::stopSound
  • PHP 手册
  • 函数参考
  • 非文本内容的 MIME 输出
  • Ming
  • SWFMovie

SWFMovie::streamMP3

(PHP 5 < 5.3.0, PECL ming SVN)

SWFMovie::streamMP3 — Streams a MP3 file

说明

SWFMovie::streamMP3 ( mixed $mp3file [, float $skip = 0 ] ) : int Warning

此函数是实验性的。此函数的表象,包括名称及其相关文档都可能在未来的 PHP 发布版本中未通知就被修改。使用本函数风险自担 。

Streams the given MP3 file mp3file.

This method is not very robust in dealing with oddities (can skip over an initial ID3 tag, but that's about it).

Note that the movie isn't smart enough to put enough frames in to contain the entire mp3 stream- you'll have to add (length of song * frames per second) frames to get the entire stream in.

参数

mp3file

Can be a file pointer returned by fopen() or the MP3 data, as a binary string.

skip

Number of seconds to skip.

返回值

Return number of frames.

更新日志

版本 说明
5.2.0 skip added

范例

Example #1 Streaming example

<?php
$m = new SWFMovie();
$m->setRate(12.0);
$m->streamMp3(file_get_contents("distortobass.mp3"));
// use your own MP3

// The file is 11.85 seconds at 12.0 fps = 142 frames
$m->setFrames(142);

header('Content-type: application/x-shockwave-flash');
$m->output();
?>
add a note

User Contributed Notes 6 notes

up down 1 boreckiwebs at gmail dot com12 years ago if you want to control the sound use these functions like this:

<?php

$m -> add(new SWFAction('
stop(); // pauses the song
goToAndStop(1); // stops the song, and goes back to the beginning
play(); // plays the song from current position
'));

?>

i hope this is helpful
up down 1 mued at muetdhiver dot org18 years ago a nice feature to handle Id3tag is to get support from Unix mp3info command into a returning exec parsing up down 0 aaronmason85 at gmail dot com10 years ago Hey all,

For those using Ming 0.3 (like me), there is a way to calculate the length of the MP3 you are using.  It might be a bit iffy for VBR files, but it seems to work well for the files I've tested thus far.  The process of calculating the frame length (and size) is detailed at http://www.mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm

<?php

function get_mp3_len ($file) {

        $rate1=array(0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, "bad");
        $rate2=array(0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, "bad");
        $rate3=array(0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, "bad");
        $rate4=array(0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, "bad");
        $rate5=array(0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, "bad");

        $bitrate=array(
                '1'  => $rate5,
                '2'  => $rate5,
                '3'  => $rate4,
                '9'  => $rate5,
                '10' => $rate5,
                '11' => $rate4,
                '13' => $rate3,
                '14' => $rate2,
                '15' => $rate1
        );

        $sample=array(
                '0'  => 11025,
                '1'  => 12000,
                '2'  => 8000,
                '8'  => 22050,
                '9'  => 24000,
                '10' => 16000,
                '12' => 44100,
                '13' => 48000,
                '14' => 32000
        );

        $fd=fopen($file, 'rb');
        $header=fgets($fd, 5);
        fclose($fd);

        $bits="";
        while (strlen($header) > 0) {

                //var_dump($header);
                $bits.=str_pad(base_convert(ord($header{0}), 10, 2), 8, '0', STR_PAD_LEFT);
                $header=substr($header, 1);
        }

        $bits=substr($bits, 11); // lets strip the frame sync bits first.

        $version=substr($bits, 0, 2); // this gives us the version
        $layer=base_convert(substr($bits, 2, 2), 2, 10); // this gives us the layer
        $verlay=base_convert(substr($bits, 0, 4), 2, 10); // this gives us both

        $rateidx=base_convert(substr($bits, 5, 4), 2, 10); // this gives us the bitrate index
        $sampidx=base_convert($version.substr($bits, 9, 2), 2, 10); // this gives the sample index
        $padding=substr($bits, 11, 1); // are we padding frames?

        $rate=$bitrate[$verlay][$rateidx];
        $samp=$sample[$sampidx];

        $framelen=0;
        $framesize=384; // Size of the frame in samples
        if ($layer == 3) { // layer 1?
                $framelen=(12 * ($rate * 1000) / $samp + $padding) * 4;
        } else { // Layer 2 and 3
                $framelen=144 * ($rate * 1000) / $samp + $padding;
                $framesize=1152;
        }

        $headerlen=4 + ($bits{4} == 0 ? '2' : '0');

        return (filesize($file) - $headerlen) / $framelen / ($samp / $framesize);
}

?>
up down 0 Richard Trigaux10 years ago Seems that this function only handles some MP3 files with specified sample rates and not others. 44100 and 21050 work. With the lame MP3 converter, this is obtained with setting the "bit rate" at 112 (average compression/quality), mono or stereo. Other values may work, probably multiples, I did not tried all. up down 0 diana11 years ago If you need to play an mp3 fully you need to do something like:

<?php
$len = $m->streamMp3(fopen("sound.mp3", "r"));
$m->setFrames($len);
?>

This works only in Ming 0.4. I'm not 100% sure but it doesn't sound to work on Ming 0.3
up down 0 boo at php dot net16 years ago Don't forget to use fopen function in example above !

Use

<?php
$m->streamMp3(fopen("distortobass.mp3", "rb"));
instead of
$m->streamMp3("distortobass.mp3");
?>

I hope this is useful for you :)
add a note

官方地址:https://www.php.net/manual/en/swfmovie.streammp3.php

  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net