Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Architecturing an Audio Player  (Read 6766 times)
ramonmaruko
Newbie
*
Posts: 2


View Profile Email
« on: November 03, 2009, 04:37:08 »

I am trying to convert/migrate my Flash audio player into Flex using PureMVC. Right now all it could do is connect to the media server(red5). This is my first PureMVC project.

Right now, the application is structured as follows:
  • MediaServerProxy which creates/manages the NetConnection object.
  • MediaServerCommand which calls the connection() function of MediaServerProxy
  • A view component(TextInput) which displays the NetStatusEvent codes

I would like some help about the following:
  • Can I still improve on how I have currently structured  the application?
  • I am stuck as to how it would be best to retrieve the playlist from red5.

    It has to call a server-side function, getListOfAvailableFLVs(), which returns a  Java type of Map<String, Map<String, Object>>. I am able to do this when it was still coded in Flash using:
:
var connection:NetConnection = new NetConnection();
//...
this.connection.call("demoService.getListOfAvailableFLVs", responder);
    An example code would be nice.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: November 03, 2009, 09:43:49 »

I'll assume you're using the Flex service configuration files1 to map your services.

In remoting-config.xml, you'll have something like:
:
<destination id="DemoService">
   <properties>
      <source>com.me.myapp.DemoService</source>
   </properties>
</destination>

If you're not already, you need to add this configuration to your Flex compiler arguments.

:
-services "C:\path\to\my\services-config.xml"Note: services-config.xml includes remoting-config.xml, there are several types of service configuration for Flex.

I don't know if you're building with Ant, Flex Builder or what, but you add this argument on the mxmlc invocation of your build script or, in Flex Builder on your Project->Properties->Flex Compiler screen, in the Additional compiler arguments field.

Then a FLVListProxy might look something like:
:
public class FLVListProxy extends Proxy
{
  public static const NAME:String = "FLVListProxy";
  public static const FLV_LIST_RETRIEVED:String = NAME+"/flvListRetrieved";
  public static const FLV_LIST_FAULT:String = NAME+"/flvListFault";

  private var demoService:RemoteObject;

  public function FLVListProxy()
  {
      super(NAME, new Array());
  }

  override public function onRegister():void
  {
      demoService= new RemoteObject("DemoService");
      demoService.getListOfAvailableFLVs.addEventListener( ResultEvent.RESULT, onGetListOfAvailableFLVs );
      demoService.addEventListener( FaultEvent.FAULT );
  }

  public function getListOfAvailableFLVs():void
  {
      demoService.getListOfAvailableFLVs();
  }

  private function onGetListOfAvailableFLVs( event:ResultEvent ):void
  {
       flvList = event.result;
       sendNotification( FLV_LIST_RETRIEVED, flvList );
  }

  private function onFault( event:FaultEvent ):void
  {
       // this handles all faults for the service, since
       // the listener was placed on the service, not the method.

       // you could also have separate fault handlers for
       // each service method by placing the listeners on the method instead
       sendNotification(FLV_LIST_FAULT, event.faultDetail );
  }

  public function onRemove():void
  {
      demoService.getListOfAvailableFLVs.removeEventListener( ResultEvent.RESULT, onGetListOfAvailableFLVs );
      demoService.removeEventListener( FaultEvent.FAULT );     
      demoService=null;
  }

  public function get flvList():Array
  {
      return data as Array;
  }

}

Hope this helps,
-=Cliff>

1 Flex docs on remoting: http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html
Logged
ramonmaruko
Newbie
*
Posts: 2


View Profile Email
« Reply #2 on: November 04, 2009, 11:03:04 »

This helps a lot! Also, I haven't used RemoteObject before so the link you have given is a great help. Thanks!  ;D
Logged
Pages: [1]
Print