簡體   English   中英

從PHP將音頻流式傳輸到Flash

[英]Streaming audio into flash from php

嗨,我想知道是否有人可以幫我這個忙...我設法收集了一些有關如何從Flash調用php來流式傳輸mp3的信息,但是我不確定我如何從閃存中流式傳輸數據。 以下是我目前擁有的代碼。

function onPlay(e:MouseEvent):void
{
    //Load file to play
    var req:URLRequest = new URLRequest("streamAudio.php");
    var urlData:URLVariables = new URLVariables();
    urlData.id = id;
    req.data = urlData;

    myMusic.load(req); //myMusic is a Sound object
    myChannel = myMusic.play(); //myChannel is a SoundChannel object

    btn_Play.visible = false;
    btn_Pause.visible = true;
}

的PHP

<?php
$ID = $_GET["id"];

if ($ID != 0)
{
    //Code to fetch URL from DB

    $url = $row["url"];
    $file = "/" . $url;

    if(file_exists($file))
    {
        header("Content-type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
        header("Content-Length: " . filesize($file));
        header("Expires: -1");
        header("Cache-Control: no-store, no-cache, must-revalidate");
        header("Cache-Control: post-check=0, pre-check=0", false);

        readfile($file);
    }

    //Close DB
}

感謝所有幫助。 提前致謝!!

編輯

修改了代碼。 如果立即進行測試,PHP腳本將起作用。

我不知道您為什么要做什么...您應該可以非常簡單地播放音頻:

s = new Sound();
s.loadSound("http://someserver/yourscript.php", true);

當然,這首先假設您的PHP腳本正在運行。 請注意,在許多情況下,下載之前無法獲得遠程資源的文件大小。 首先直接點擊它來測試您的PHP腳本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM