Home  >  

Composition and the Player Swapper

Author photo
August 17, 2009 | | Comments (0)
AddThis Social Bookmark Button

Around a year ago I was given the task to create an architecture for a syndicatable video player, capable of playing any video that might be served up by our different products. The first thing I had to do was constrain that requirement to a list of predetermined video types - we have different video classes, sub-classed by what advertising system they use or what product plays them. They were all FLV, but for two of the video types we were contractually obligated to load a third party player to play the video.

Once I knew the types of videos I would allow and the players that I would need I came up with an interface that would encompass all of the capabilities of each player. I called this IPlayer.

IPlayer_firstdraft.png

I knew that I wanted my architecture to allow me to switch between any of the players, and should make each piece interchangeable from the next. Not that I would, but in theory, if I had a play list of only one type of video objects I should be able to instantiate just the wrapper for that player and have it function the same way as the player swapper in my over all application.

With this in mind I knew that I would need to have every piece in the architecture implement the interface, not just the player wrappers. I decided it would make more sense to use composition to delegate the functionality promised in the interface, rather than direct implementation. So I added an instance of IPlayer to the interface:

IPlayer.png

I then created a wrapper for each external player that implemented the interface. I also created the implementation for a player swapper and player controller both implementing the interface. The player controller receives a play list as an array of IVideos and steps through the play list passing each IVideo to the player swapper. The player swapper keeps a list of IPlayers and decides which one to use based on the meta data inside the IVideo. Once those early design decisions were made, the architecture almost wrote itself:

playerswapper.png

In my next article I'll discuss how I managed memory with the player swapper.

Read more from Tom Barker. Tom Barker's Atom feed

Comments

Leave a comment


Tag Cloud

iPad

What's your take on the iPad? (Putting aside the Flash/iPad flame war)

Answer

Latest Features

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.