Chris R
Chris R

Reputation: 17926

How can I call an AMF service using Flex and get back an MP3?

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:

  1. Provide data to the Sound object's load method from a RemoteObject service call.
  2. 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.
  3. Any alternative that allows me to invoke a PHP4 AMF service and play the audio it returns in a Flash audio player.

Upvotes: 4

Views: 549

Answers (3)

Matt
Matt

Reputation: 3652

You need to load the Sound from a ByteArray which is done here:

http://www.flexiblefactory.co.uk/flexible/?p=46

Upvotes: 1

warhammerkid
warhammerkid

Reputation: 955

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.

Upvotes: 3

JeffryHouser
JeffryHouser

Reputation: 39408

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.

Upvotes: 0

Related Questions