How can I call AMF using Flex and return the MP3?

My Flex 3.5 application has an audio player that is accessed by calling the AMF service to retrieve mp3 data. As far as I can tell, flash.media.Sound initialized using URLRequest , so it’s not clear to me how I can provide data using RemoteObject .

I want to do one of the following:

  • Providing data to the Sound method of the load object from a call to the RemoteObject service.
  • Create a URLRequest object that will perform the required AMF processing so that my service implementation looks just like any other service call, if at all possible.
  • Any alternative that allows me to call the PHP4 AMF service and play the sound that it returns in the Flash player.
+4
source share
3 answers

If you absolutely must use AMF to deliver sound, you have 2 options. The first is to wrap the MP3 in swf, send it back as ByteArray, and use the loadBytes method on Loader to load it back. The second option is to convert it to wav, send it as a ByteArray, and then parse the audio file and feed the data using the sampleData event (Flash Player 10 only). I would probably recommend the first option, since it is much simpler and faster than the second, but both of them are not particularly easy.

If I had to authenticate through AMF to download the sound, I would return some kind of session cookie and set up a simple PHP service that will serve MP3 files with the appropriate cookie session.

+3
source

You need to load the sound from ByteArray, which is done here:

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

+1
source

Why not use a Sound object with a URL parameter?

No need to write code to manually get the URL. If you prefer to do the reverse processing before returning the file, you can simply set the return type to mimetype and "upload" bytes of mp3 file data to the output stream.

With ColdFusion, this is easy to use with the cfcontent tag. I assume that PHP offers some parallel, but I do not know what it is.

0
source

Source: https://habr.com/ru/post/1314884/


All Articles