Packagecom.soma.view.video.controls
Classpublic class SomaVideoControls
InheritanceSomaVideoControls Inheritance flash.display.Sprite

Author: Romuald Quantin - www.soundstep.com

Information:
Blog page - SomaUI
How does it work - Soma Protest
Project Host - Google Code
Documentation - Soma ASDOC
Class version: 2.0
Actionscript version: 3.0

Copyright:

The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied.
See the License for the specific language governing rights and
limitations under the License.

The Original Code is Soma.
The Initial Developer of the Original Code is Romuald Quantin.
Initial Developer are Copyright (C) 2008-2009 Soundstep. All Rights Reserved.

Usage:
The SomaVideoControls handles default controls or an undefined number of controls added to this class. SomaVideoControls is extending a Sprite and be accessed through the "controls" property of a SomaVideoPlayer instance.

Everytime a control is added to the instance, it will layout them from left to right (and strech the time bar when the property fitToVideo is set to true). You have some properties to reach common layouts:

The following code is reproducing how the default controls are added in the SomaVideoControls class (by default).
var controls:SomaVideoControls = new SomaVideoControls();
controls.addControl(new SomaVideoPlaySkin());
controls.addControl(new SomaVideoTimeBarSkin());
controls.addControl(new SomaVideoMuteSkin());
controls.addControl(new SomaVideoFullscreenSkin());
var player:SomaVideoPlayer = new SomaVideoPlayer("video/video.flv", controls);
addChild(player);
     
See each default skin class link below to see examples, how to change the defaut skins and create custom skins. Each controls is working with 2 classes, a view skin class (receiver) a controller class (sender). The controller is getting the data needed to display the skin information and send it to the skin.

For example, the default skin SomaVideoPlaySkin is receiving data from a PlayController class (com.soma.view.video.controls.PlayController).

Here is how the default controls are internally added to the SomaVideoControls instance:
addSkinController(PlayController, ISomaVideoPlaySkin);
addSkinController(MuteController, ISomaVideoMuteSkin);
addSkinController(FullscreenController, ISomaVideoFullscreenSkin);
addSkinController(TimeBarController, ISomaVideoTimeBarSkin);
     
The skin system is flexible enough to make you able to add your own controllers and skins, following some rules. Let's take the example that you want to build a buffer skin included in the bar, which is not built by default in a SomaVideoPlayer instance.

Build your own skin class Build your own controller class This is the skeleton structure to be accepted by the SomaVideoControl instance. You can know built the logic, as you have a SomaVideoPlayer instance in the Controller (BufferController), you can add some listeners and send the information needed to the skin class. The skin will receive them and display then the way you wish.

IBufferSkin interface
package {

    import com.soma.view.video.controls.ISomaVideoSkin;
    
    public interface IBufferSkin extends ISomaVideoSkin {
        
        function bufferCallBack(bufferLength:Number, bufferTime:Number):void;
        
    }
}
     
BufferSkin class
package com.somaprotest {
    import com.soma.view.video.SomaVideoPlayer;
    import flash.display.Sprite;

    public class BufferSkin extends Sprite implements IBufferSkin {
        
        private var _player:SomaVideoPlayer; 

        public function BufferSkin() {
            createSkinElements();
        }
        
        private function createSkinElements():void {
            // create graphic skin element here
            
        }
        
        public function bufferCallBack(bufferLength:Number, bufferTime:Number):void {
            // handle graphic skin elements with the data received
            trace("BUFFERING > bufferLength: ", bufferLength, ", bufferTime: ", bufferTime);
        }
        
        public function registerPlayer(player:SomaVideoPlayer):void {
            _player = player;
        }
        
        public function dispose():void {
            // This method is internally called when you dispose a SomaVideoPlayer
            // to remove children, the event listeners or whatever that needs to be
            // destroyed to free the memory (make the instance elligible to the
            // Garbage Collection).
        }
        
    }
}
     
BufferController class
package com.somaprotest {
    import com.soma.view.video.events.SomaVideoEvent;
    import com.soma.view.video.SomaVideoPlayer;
    import com.soma.view.video.controls.ISomaVideoDisposable;

    public class BufferController implements ISomaVideoDisposable {
        
        private var _videoPlayer:SomaVideoPlayer;
        private var _skin:IBufferSkin;
        
        public function BufferController(videoPlayer:SomaVideoPlayer, skin:IBufferSkin) {
            _videoPlayer = videoPlayer;
            _skin = skin;
            _videoPlayer.addEventListener(SomaVideoEvent.BUFFERING_START, eventsHandler);
            _videoPlayer.addEventListener(SomaVideoEvent.BUFFERING_PROGRESS, eventsHandler);
            _videoPlayer.addEventListener(SomaVideoEvent.BUFFERING_COMPLETE, eventsHandler);
        }
        
        public function eventsHandler(e:SomaVideoEvent):void {
            _skin.bufferCallBack(_videoPlayer.bufferLength, _videoPlayer.bufferTime);
        }

        public function dispose():void {
            _videoPlayer.removeEventListener(SomaVideoEvent.BUFFERING_START, eventsHandler);
            _videoPlayer.removeEventListener(SomaVideoEvent.BUFFERING_PROGRESS, eventsHandler);
            _videoPlayer.removeEventListener(SomaVideoEvent.BUFFERING_COMPLETE, eventsHandler);
        }
        
    }
    
}

     
Add the custom controller and its skin, and finally, add the skin itself.
var controls:SomaVideoControls = new SomaVideoControls();
controls.addSkinController(BufferController, IBufferSkin);
controls.addControl(new BufferSkin());
var player:SomaVideoPlayer = new SomaVideoPlayer("video/video.flv", controls);
addChild(player);
     

See also

Soma
SomaVideo
SomaVideoPlayer
SomaVideoEvent
SomaVideoControls
SomaVideoPlaySkin
SomaVideoTimeBarSkin
SomaVideoMuteSkin
SomaVideoFullscreenSkin


Public Properties
 PropertyDefined by
  alignBottom : Boolean
Specifies whether the controls are aligned to the bottom or to the top (default true).
SomaVideoControls
  backgroundAlpha : Number
Specifies the background transparency of the controls (default alpha 0.5).
SomaVideoControls
  backgroundColor : uint
Specifies the background color of the controls (default black).
SomaVideoControls
  fitToVideo : Boolean
Specifies whether the width of the controls will fit to the video width (set this property to false to have a complete control of the size and position), default true.
SomaVideoControls
  margin : Number
Specifies the margin around the skin (default is 5).
SomaVideoControls
  sitOnVideo : Boolean
Specifies whether the controls are "on" or "outside" the video screen (default true).
SomaVideoControls
Public Methods
 MethodDefined by
  
create a SomaVideoControls instance.
SomaVideoControls
  
addControl(control:ISomaVideoSkin):void
Add a control to the list, example: SomaVideoPlaySkin.
SomaVideoControls
  
addSkinController(controllerClass:Class, skinInterface:Class):void
Add a controller and its skin.
SomaVideoControls
  
dispose():void
This method is internally called when you dispose a SomaVideoPlayer to remove children, the event listeners or whatever that needs to be destroyed to free the memory (make the instance elligible to the Garbage Collection).
SomaVideoControls
  
draw():void
Draw (layout) the controls.
SomaVideoControls
  
getControl(classType:Class):ISomaVideoSkin
Get a control using the class.
SomaVideoControls
Property detail
alignBottomproperty
alignBottom:Boolean  [read-write]

Specifies whether the controls are aligned to the bottom or to the top (default true).

Implementation
    public function get alignBottom():Boolean
    public function set alignBottom(value:Boolean):void
backgroundAlphaproperty 
backgroundAlpha:Number  [read-write]

Specifies the background transparency of the controls (default alpha 0.5).

Implementation
    public function get backgroundAlpha():Number
    public function set backgroundAlpha(value:Number):void
backgroundColorproperty 
backgroundColor:uint  [read-write]

Specifies the background color of the controls (default black).

Implementation
    public function get backgroundColor():uint
    public function set backgroundColor(value:uint):void
fitToVideoproperty 
fitToVideo:Boolean  [read-write]

Specifies whether the width of the controls will fit to the video width (set this property to false to have a complete control of the size and position), default true.

Implementation
    public function get fitToVideo():Boolean
    public function set fitToVideo(value:Boolean):void
marginproperty 
margin:Number  [read-write]

Specifies the margin around the skin (default is 5).

Implementation
    public function get margin():Number
    public function set margin(value:Number):void
sitOnVideoproperty 
sitOnVideo:Boolean  [read-write]

Specifies whether the controls are "on" or "outside" the video screen (default true).

Implementation
    public function get sitOnVideo():Boolean
    public function set sitOnVideo(value:Boolean):void
Constructor detail
SomaVideoControls()constructor
public function SomaVideoControls()

create a SomaVideoControls instance.

Method detail
addControl()method
public function addControl(control:ISomaVideoSkin):void

Add a control to the list, example: SomaVideoPlaySkin.

Parameters
control:ISomaVideoSkin
addSkinController()method 
public function addSkinController(controllerClass:Class, skinInterface:Class):void

Add a controller and its skin.

Parameters
controllerClass:Class — A class.
 
skinInterface:Class — A class.
dispose()method 
public function dispose():void

This method is internally called when you dispose a SomaVideoPlayer to remove children, the event listeners or whatever that needs to be destroyed to free the memory (make the instance elligible to the Garbage Collection).

draw()method 
public function draw():void

Draw (layout) the controls.

getControl()method 
public function getControl(classType:Class):ISomaVideoSkin

Get a control using the class.

Parameters
classType:Class — A Class.

Returns
ISomaVideoSkin — A Class typed ISomaVideoSkin.