View Full Version : Video Player as OOP project

Flash Gordon
08-30-2007, 10:33 PM
Hi Guys,

I'm okay with code, so I'm not asking about that. However, I'd like to get a little help with coming up with a OOP structure for a video player; you know, just the standard youtube player.

From what I've learn so far I can rule out the use of several patterns:
Factory - doesn't seem to be any need for a factory
Adapter - I'm creating the code from scratch so no need.
Iterator - I won't be storing any list of data, and if I do it will be xml
Composite - I wont be having grouping of videos with sub videos so that is out.
State - while there will be different states of the player (playing, paused), i don't think this pattern will be used
Facade - i could use it, but i think it is over kill
Decorator - i don't see how right now

So that leaves me with:
Observer - this is built into the way flash event handling
Strategy - maybe?
Command - eh.....

But I also want to keep in mind (and what I haven't in the the past) is "A class should have only one reason to change" e.g. 1 class 1 job.

Could I get some help how to make a OO video player

Flash Gordon
09-01-2007, 04:11 AM
I've just started reading about MVC, and that seems like the perfect design. Though I'm up for discussion.......

Flash Gordon
09-03-2007, 06:00 AM
Well....i think I'll do it 2 ways for fun:

State Pattern

10-22-2007, 05:33 AM
I am working on the same project. How has it been going?

I definitely see using the state pattern, but I'm not sure exactly how it fits into an mvc pattern. For example, I'm thinking that the model would be the context in the state pattern, and that the controllers would be the states.

The view would be the user interface. Would each ui element be a view? I'm working on the code but I'm not sure how it will all work in the end. Is there a pattern for the views calling the controllers? Or do you just hard code that in, since you're dealing with ui elements using flash event handling?

Also, I'm looking at using the Observer pattern as well. The model would be the subject in the observer pattern, with the views being the observers.

Flash Gordon
10-22-2007, 06:39 AM
on the adobe site, they have a tutorial how to do it as a state pattern. It looked pretty stupid to me. The MVC turned out great.

10-23-2007, 05:11 PM
So which patterns did you use?

Also, why did the state pattern not work for you? (I'm not looking to debate any particular pattern, just curious about your experience.)

Flash Gordon
10-23-2007, 06:03 PM
Adobe State Pattern Tutorial (http://www.adobe.com/devnet/flashmediaserver/articles/video_state_machine_as3.html)

I used MVC. State Pattern doesn't make sense to me for this. There really are no "states" for a video player.

10-23-2007, 06:13 PM
I'm guess I'm looking for various code examples. So you used an mvc framework like this? Colin Moock provides some class files for implementing mvc.


If you could post any example code, I would greatly appreciate it!

Can I see your video player online as well? Let's see your handy work :)

Flash Gordon
10-23-2007, 07:09 PM
The video player is propritary. I can't give you any help there, other than just guiding you.

Your best best is just to start coding it in several pattern and find the limitations yourself. For me and what I wanted, MVC made the most sense. You may have different needs.

10-23-2007, 09:10 PM
Not looking for anything for free. Just some code examples. So I didn't mean to imply that. I couldn't post any code from actual production projects either. :p

If anyone would like to post some examples of design patterns they have used and found suited to a video player, I would appreciate it.

For example, to me, in the mvc pattern, it makes sense to use the observer pattern between the view and the model, with the model being the subject and view being the observer. So, within mvc, there are multiple design patterns used to implement mvc. That's my understanding. I working this out in uml and I would be glad to post selected examples later.

04-24-2009, 08:18 PM
I disagree there a various states for a video player. Playing, Stopped, Pause and maybe Resume. However, I don't disagree that a video player is a good candidate for an MVC. I am very torn on which way to go here, both seem like a good option. The original post goes back a couple years, I'm curious to know how you feel about the subject now.

I am currently working on a video player that needs to have subtitles display that are driven from XML. other features are pretty equal to a youtube video player. So I really need to have an MVC in place, are there any open source frameworks you would recommend for this?

Flash Gordon
04-25-2009, 08:34 AM
Hi friend,

Design patterns aren't so 2 dimension as I once thought, but if I were to simplify it, there is no other correct options than MVC. And here's my break down:
Model - handles the loading of the netstream, progressing, scrubbing yada yada
View - simple renders the model's information in whatever it see fits. In this case it is a Video instance, pause, play, stop btns and a video progress bar.
Controller - interprets the views click Events, and calls the methods on the model. Here's some stub code for you


private var nc:NetConnection;
private var ns:NetStream:

public function play():void { }
public function seek(time:Number):void { }
public function stop():void { }
public function togglePause():void;
public function dispose():void; { }


public function play():void { model.play() }
public function seek(time:Number):void { model.seek(time) }
public function stop():void { model.stop() }
public function togglePause():void;
public function dispose():void; { }

private function view_playHandler(e:Event):void

private function view_seekHandler(e:IndexEvent):void
// .... etc


// just a display object or an event dispatcher which aggregates objects in

In my case if I want to interact with "the system" (my video player), I only call methods on the controller. I try to avoid method calls on the model directly from outside my controller.

Now where I said it isn't so 2 dimensional is, if you have trouble finding yourself managing the state on the video player, your view or controller could use a state machine to control user interaction. For instance, when in a stopped state, pressing the stop button would do nothing. In a playing state it would stop. However, I think the state pattern is completely unnecessary for a video player and it's a HORRIBLE example by design patterns for AS 3.

So to answer your last question, no of course you don't need an MVC, you never need a design pattern. And I don't know of any frameworks for video players.