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: Q;Architecting a PureMVC Video Player  (Read 7698 times)
eco_bach
Courseware Beta
Sr. Member
***
Posts: 81


View Profile Email
« on: September 03, 2009, 11:11:50 »

For my next project I'd like to create a modular video player using puremvc.

Obviously a case for Final State Machine, but confused about proxies and mediators.

What should the function of a proxy be (in a videoplayer)?


« Last Edit: September 09, 2009, 02:40:39 by eco_bach » Logged
Mirux
Jr. Member
**
Posts: 11


View Profile Email
« Reply #1 on: September 03, 2009, 07:51:15 »

Proxies are the one who brings external data to the system. So managing the states in proxies should not be proxies duty. You could manage states in mediators instead.

I think it will depend on the logic of your custom components. If a component has a lot of stuff to interact with, sometimes it is better to isolate it and create a mediator that deals with all the interactions and notify to a command if you need more complex logic.

I got started a few days ago with PureMVC and so far, I think it is pretty straight forward. I see it like this:

Components
Visual part, user interacts with it. Every interaction dispatches an event WHICH a mediator can handle. If this component have several ways to interact with, then it would be probably a better choice to create a mediator for this component, otherwise you could always use the component's parent mediator.

Mediator
These are the ones responsible to handle interactions between the user and a component. A component does not know a mediator exists, only the mediator knows the component exist. Mediators could retrieve. You could handle lightweight logic in mediators, but heavier logic, you shall delegate this to a command.

Command
Well, I see these as literal "commands" you call for a certain action. For example, I have an application which have actions like: AddClient, EditClient. I usually connect one command to a proxy. The command retrieves the proxy to call a remote object, save client to database, edit client info, etc.

Commands for me are like a bridge between Mediators and Proxy. I don't like the idea of retrieving Proxys directly from Mediators, I like using Commands instead. A command for each action.

Proxies
These guys are brings the fun to the application. they load data, query local db (AIR), remote objects, load assets, etc. And pass it on to the command in case you need to do some logic before pass it to the mediator.

I'd love and really appreciate someone can correct myself if I didn't get something straight, but so far, this is how I understand PureMVC.

Edit: Sorry echo_bach, but in your case what I'd do is, create mediators for complex components, to deal with their interactions as custom as I could, giving your application even more flexibility.

Handle states in proxy??? Nah, you can do this in mediators. so if your <mx:Application> have several states, you might want to create a "ApplicationMediator", which you register in the startup command.

A good practice would be, make StartupCommand a MacroCommand, and then in this MacroCommand, you add two subcommands: "SetupViewCommand" and "SetupModelCommand".

In SetupModelCommand you register the proxies you will be using and in the SetupViewCommand you register the mediators, which is a perfect place to register the ApplicationMediator.

If you need a clear example of this, you can check this PDF: http://puremvc.org/component/option,com_wrapper/Itemid,174/
« Last Edit: September 08, 2009, 07:07:38 by Mirux » Logged
eco_bach
Courseware Beta
Sr. Member
***
Posts: 81


View Profile Email
« Reply #2 on: September 08, 2009, 06:52:17 »

Thanks Mirux, appreciate the reply but wasn't asking for an overview of PureMVC.

My question is about architecting a PureMVC Video Player, especially the role of a proxy-model outside of say, parsing a video playlist.

Should there be a separate 'NetstreamProxy', and if so, can someone list any specific advantages of why it would make sense to refactor the NetStream related code into its own class?
« Last Edit: September 09, 2009, 02:38:08 by eco_bach » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: September 09, 2009, 07:53:04 »

Although the data (flv) is coming into the app via a NetStream object (indicating a Proxy), you'd likely be better off wrapping it in a Mediator and treating it as a view component. Just like an Image control that you set a source property for, the image control loads its own data. You just need to worry about telling it what to load.

Even better would be to encapsulate the NetStream inside the video player component, and simply expose properties for the data it needs such as the URL. There's probably no real reason for the NetStream to be independent of the video player component.

-=Cliff>
Logged
eco_bach
Courseware Beta
Sr. Member
***
Posts: 81


View Profile Email
« Reply #4 on: September 09, 2009, 01:22:13 »

Thanks Cliff!
I've seen examples of video players refactoring the Netstream creation and configuration into a proxy-model , and I've tried to do something similar but it really seemed counter-intuitive, as well as adding an unnecessary layer of complexity. Most importantly it also seemed to go against one of the primary goals of MVC, maintaining true portability and independence of the view components.
However, I think a videoplayer is a great example of an application that would make great use of the State pattern, and will definitely try to incorporate the FSM.

I'll reserve proxy use for cases where I'm loading an xml or external playlist.
« Last Edit: September 09, 2009, 01:26:53 by eco_bach » Logged
Pages: [1]
Print