如何使用 Flex 调用 AMF 服务并取回 MP3?
我的 Flex 3.5 应用程序有一个音频播放器,通过调用 AMF 服务来获取 mp3 数据来访问其内容。据我所知, flash.media.Sound
是使用 URLRequest
初始化的,因此我不清楚如何使用我的 为其提供数据远程对象
。
我想要执行以下操作之一:
- 通过
RemoteObject
服务调用向Sound
对象的load
方法提供数据。 - 创建一个
URLRequest
对象,该对象将执行必要的 AMF 包装,以便我的服务实现在可能的情况下看起来与任何其他服务调用完全相同。 - 任何允许我调用 PHP4 AMF 服务并在 Flash 音频播放器中播放它返回的音频的替代方案。
My flex 3.5 application has an audio player whose content is accessed by calling an AMF service to get the mp3 data. As far as I can tell, flash.media.Sound
is initialized with a URLRequest
, so it's not clear to me how I can provide it with data using my RemoteObject
.
I want to do one of the following things:
- Provide data to the
Sound
object'sload
method from aRemoteObject
service call. - Create a
URLRequest
object that will perform the requisite AMF wrapping so that my service implementation will look exactly like any other service call if at all possible. - Any alternative that allows me to invoke a PHP4 AMF service and play the audio it returns in a Flash audio player.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您绝对必须使用 AMF 来提供声音,您有 2 个选择。第一种是将 MP3 包装在 swf 中,将其作为 ByteArray 发送回来,然后使用 Loader 上的 loadBytes 方法将其加载回来。第二个选项是将其转换为 wav,将其作为 ByteArray 发送,然后解析音频文件并使用 SampleData 事件将数据提供给声音(仅限 Flash Player 10)。我可能会推荐第一个选项,因为它比第二个选项更容易、更快,但两者都不是特别容易。
如果我必须通过 AMF 进行身份验证才能加载声音,我将返回某种类型的会话 cookie,并设置一个简单的 PHP 服务,该服务将使用正确的会话 cookie 来提供 MP3。
If you absolutely have to use AMF to serve the sound, you have 2 options. The first is to wrap the MP3 in a swf, send it back as a ByteArray and use the loadBytes method on Loader to load it back in. The second option is to convert it to a wav, send it as a ByteArray, and then parse the audio file and feed the data to a sound using the sampleData event (Flash Player 10 only). I would probably recommend the first option, as it's a lot easier and faster than the second, but both aren't particularly easy.
If I had to authenticate through AMF to load sound, I would return a session cookie of some type and set up a simple PHP service that would serve MP3s with the proper session cookie.
您需要从此处完成的 ByteArray 加载声音:
http://www .flexiblefactory.co.uk/flexible/?p=46
You need to load the Sound from a ByteArray which is done here:
http://www.flexiblefactory.co.uk/flexible/?p=46
为什么不将 Sound 对象与网址参数?
无需编写代码来手动检索您的 URL。如果您希望在返回文件之前进行一些后端处理,则只需设置返回 mimetype 并将 mp3 文件的数据字节“转储”到输出流中即可。
对于 ColdFusion,使用 cfcontent 标签可以轻松实现这一点。我认为 PHP 提供了一些并行,但我不知道它是什么。
Why not use the Sound object with a URL parameter?
No need to write code to manually retrieve your URL. If you prefer to do some back end processing before returning the file, you can just set the return mimetype and 'dump' the data bytes of the mp3 file into the output stream.
With ColdFusion, this is easy using the cfcontent tag. I assume PHP offers some parallel, however I don't know what it is.