0

だから私はmp3ファイルを生成しています、そしてそれをダウンロードすると私はそれをうまく再生できるのでそれはうまく機能しています、しかし今私がしたいのは私のブラウザにそのファイルを出力して私のブラウザでそれを再生することです、それで私が試したことは:

header("Pragma: no-cache");
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Content-Type: audio/mepeg');
header("Content-Disposition: attachment; filename=\"validate.mp3\"");
header("Content-Transfer-Encoding: binary");
header("Content-length: $size");

<embed autoplay="true" height="0" width="0" src="actions/play_file"  />

もちろんIDは機能しません。使用したことがあるので、そのファイルを強制的にダウンロードするだけです。

"Content-Disposition: attachment; filename=\"validate.mp3\"")

そして、私がこれに正しいhtmlタグを使用しているかどうかは確かですか?しかし、私がそうであれば、私が必要とするのは、これを機能させるための適切なヘッダーだけです。

4

3 に答える 3

1

ファイルをフィードする方法は次のとおりです。

header("Content-type: audio/mpeg");
header("Content-length: " . filesize($file));
header("Cache-Control: no-cache");
header("Content-Transfer-Encoding: binary"); 
readfile($file);

またはチャンクで

$total     = filesize($filepath);
$blocksize = (2 << 20); //2M chunks
$sent      = 0;
$handle    = fopen($filepath, "r");

// Push headers that tell what kind of file is coming down the pike
header('Content-type: '.$content_type);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-length: '.$filesize * 1024);

// Now we need to loop through the file and echo out chunks of file data
// Dumping the whole file fails at > 30M!
while($sent < $total){
    echo fread($handle, $blocksize);
    $sent += $blocksize;
}

exit(0);
于 2012-09-27T16:57:12.367 に答える
1

重要なことは、Content-Typeヘッダーを指定することです。ブラウザ(または他のユーザーエージェント)がそれを使って何をするかは、あなたではなく、彼ら次第です。現在使用しているコンテンツタイプが正しくありません。を使用しaudio/mpegます。

常に再生する唯一の方法は、Webページにプレーヤーを含めることです。そのためには、HTML5オーディオタグ、Flash、埋め込みなどを使用できます。

于 2012-09-27T17:04:12.463 に答える
0

...そしてさらに...もう1つのより単純なアプローチ...2013年1月24日にIvonaという名前のポーランドの会社がAmazonに買収された瞬間からこのアプローチをテストしたので、うまくいくことが証明されていますAWS Pollyのクレデンシャルを設定した後、ボックスの

    header('Accept-Ranges: none');
    header('Content-Type: audio/mpeg');

    echo $audio;
于 2021-10-09T15:54:02.437 に答える