简体   繁体   English

从PHP将音频流式传输到Flash

[英]Streaming audio into flash from php

Hi i was wondering if someone could give me a hand with this... I've managed to gather some information on how to call php from flash to stream the mp3 however im not exactly sure how i go about streaming the data from flash. 嗨,我想知道是否有人可以帮我这个忙...我设法收集了一些有关如何从Flash调用php来流式传输mp3的信息,但是我不确定我如何从闪存中流式传输数据。 Below is the code i currently have. 以下是我目前拥有的代码。

Flash

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

<?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
}

All help is appreciated. 感谢所有帮助。 Thanks in advance!! 提前致谢!!

EDIT 编辑

Modified the code. 修改了代码。 The PHP script works if tested directly now. 如果立即进行测试,PHP脚本将起作用。

I don't know why you're doing what you're doing... you should be able to play the audio very simply: 我不知道您为什么要做什么...您应该可以非常简单地播放音频:

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

This of course assumes your PHP script is working in the first place. 当然,这首先假设您的PHP脚本正在运行。 Note that in many cases, you cannot get the file size of a remote resource prior to downloading it. 请注意,在许多情况下,下载之前无法获得远程资源的文件大小。 Test your PHP script first by hitting it directly. 首先直接点击它来测试您的PHP脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM