Packagecom.soma.view.video
Classpublic class SomaVideoPlayer
InheritanceSomaVideoPlayer 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:
SomaVideoPlayer is a wrapper that is containing 2 layers: the video (playerInstance.video) and the skinned controls (playerInstance.controls). The controls layers is a instance of the SomaVideoControls and will handle controls such play/pause, timebar, mute, and so on. SomaVideoPlayer is providing basic skinned controls by default but your can add your own.

Simple video player with a default skin.

var player:SomaVideoPlayer = new SomaVideoPlayer("video/video.flv");
addChild(player);
     
Simple video player with only a mute button and a time bar control.
var controls:SomaVideoControls = new SomaVideoControls();
controls.addControl(new SomaVideoMuteSkin());
controls.addControl(new SomaVideoTimeBarSkin());
var player:SomaVideoPlayer = new SomaVideoPlayer("video/video.flv", controls);
addChild(player);
     
Simple video player with some controls options changed.
var player:SomaVideoPlayer = new SomaVideoPlayer("video/video.flv");
player.controls.alignBottom = false;
player.controls.backgroundColor = 0xFF0000;
player.controls.backgroundAlpha = .5;
player.controls.margin = 5;
player.controls.sitOnVideo = false;
addChild(player);
     
Simple video player with soma controls that does not fit with the video (you have the control of the SomaVideoControls class).
var player:SomaVideoPlayer = new SomaVideoPlayer("video/video.flv");
player.controls.fitToVideo = false;
player.controls.backgroundColor = 0xFF0000;
player.controls.backgroundAlpha = .5;
player.controls.x = 10;
player.controls.y = 10;
player.controls.width = 200;
addChild(player);
     
Change a specific default skin option.
The skin class created by default and you can retrieve using the getControl methods are:
var player:SomaVideoPlayer = new SomaVideoPlayer("video/video.flv");
var timebar:SomaVideoTimeBarSkin = player.controls.getControl(SomaVideoTimeBarSkin) as SomaVideoTimeBarSkin;
timebar.barHeight = 5;
timebar.backgroundColor = 0xFF0000;
timebar.backgroundAlpha = .5;
timebar.timeBarColor = 0x0000FF;
addChild(player);
     
See the SomaVideoControls documentation to create your own controls.

See also

Soma
SomaVideo
SomaVideoEvent
SomaVideoControls
SomaVideoPlaySkin
SomaVideoTimeBarSkin
SomaVideoMuteSkin
SomaVideoFullscreenSkin


Public Properties
 PropertyDefined by
  autoStart : Boolean
[read-only] Specifies whether the video will automatically start playing once ready.
SomaVideoPlayer
  bufferLength : Number
[read-only] Get the length in seconds of the buffer, the "buffer length" will reach the "buffer time" before playing the video, you can get the information on a SomaVideoEvent.BUFFERING_START, SomaVideoEvent.BUFFERING_PROGRESS and SomaVideoEvent.BUFFERING_COMPLETE event.
SomaVideoPlayer
  bufferPercentage : Number
[read-only] Get the percentage of the buffer (seconds loaded), the "buffer length" will reach the "buffer time" before playing the video, you can get the information on a SomaVideoEvent.BUFFERING_START, SomaVideoEvent.BUFFERING_PROGRESS and SomaVideoEvent.BUFFERING_COMPLETE event.
SomaVideoPlayer
  bufferTime : Number
Buffer value in seconds, the default (flash built-in default of the NetStream class) is 0.1 (tenth of a second).
SomaVideoPlayer
  bytesLoaded : Number
[read-only] Get the bytes loaded of the video (preloading), you can get the information on a SomaVideoEvent.PRELOADING_START, SomaVideoEvent.PRELOADING_PROGRESS and SomaVideoEvent.PRELOADING_COMPLETE event.
SomaVideoPlayer
  bytesTotal : Number
[read-only] Get the bytes total that the video will preload, you can get the information on a SomaVideoEvent.PRELOADING_START, SomaVideoEvent.PRELOADING_PROGRESS and SomaVideoEvent.PRELOADING_COMPLETE event.
SomaVideoPlayer
  controls : SomaVideoControls
[read-only] Get the SomaVideoControls instance used to display the controls (play, mute, time bar, and so on).
SomaVideoPlayer
  duration : Number
[read-only] Get the time length (seconds) of the video, only available after that an event SomaVideoEvent.METADATA_UPDATE has been dispatched.
SomaVideoPlayer
  fullscreen : Boolean
State of the fullscreen mode.
SomaVideoPlayer
  fullscreenRect : Rectangle
Rectangle used to display the video in a fullscreen state, the default rectangle is the player itself.
SomaVideoPlayer
  height : Number
[write-only] Indicates the height of the SomaVideoPlayer instance, in pixels.
SomaVideoPlayer
  loop : Boolean
Specifies whether the video will replay on its own when it reaches the end.
SomaVideoPlayer
  pan : Number
Pan (panning) of the video, the range is -1 (for left) to 1 (for right) and the default is 0.
SomaVideoPlayer
  preloadingPercent : Number
[read-only] Get the percentage of the video that is preloaded (0 to 100), you can get the information on a SomaVideoEvent.PRELOADING_START, SomaVideoEvent.PRELOADING_PROGRESS and SomaVideoEvent.PRELOADING_COMPLETE event.
SomaVideoPlayer
  smoothing : Boolean
Specifies whether the video should be smoothed (interpolated) when it is scaled.
SomaVideoPlayer
  time : Number
[read-only] Get the current position of the playhead.
SomaVideoPlayer
  url : String
[read-only] Get the url of the video.
SomaVideoPlayer
  video : SomaVideo
[read-only] Get the SomaVideo instance used to display the video.
SomaVideoPlayer
  videoHeight : Number
Indicates the height of the video (not the player).
SomaVideoPlayer
  videoWidth : Number
Indicates the width of the video (not the player).
SomaVideoPlayer
  volume : Number
Volume of the video, the range is 0 to 1 and the default is 1.
SomaVideoPlayer
  width : Number
[write-only] Indicates the width of the SomaVideoPlayer instance, in pixels.
SomaVideoPlayer
Public Methods
 MethodDefined by
  
SomaVideoPlayer(url:String = null, controls:SomaVideoControls = null, autoStart:Boolean = true, loop:Boolean = false)
Create a SomaVideoPlayer instance.
SomaVideoPlayer
  
dispose():void
Call this method when you dispose a SomaVideoPlayer to remove children, event listeners or whatever that needs to be destroyed to free the memory (make the instance elligible to the Garbage Collection).
SomaVideoPlayer
  
heightVideoKeepingRatio(value:Number):void
Set the height of the video (not the player), the width will be updated keeping the ratio of the video source.
SomaVideoPlayer
  
pause():void
Pause the video.
SomaVideoPlayer
  
play():void
Play the video.
SomaVideoPlayer
  
resume():void
Resume the video.
SomaVideoPlayer
  
seek(time:Number):void
Move the video playhead to a (approximate) time.
SomaVideoPlayer
  
setSource(url:String):void
Set the source to play.
SomaVideoPlayer
  
stop():void
Stop the video.
SomaVideoPlayer
  
widthVideoKeepingRatio(value:Number):void
Set the width of the video (not the player), the height will be updated keeping the ratio of the video source.
SomaVideoPlayer
Property detail
autoStartproperty
autoStart:Boolean  [read-only]

Specifies whether the video will automatically start playing once ready.

Implementation
    public function get autoStart():Boolean
bufferLengthproperty 
bufferLength:Number  [read-only]

Get the length in seconds of the buffer, the "buffer length" will reach the "buffer time" before playing the video, you can get the information on a SomaVideoEvent.BUFFERING_START, SomaVideoEvent.BUFFERING_PROGRESS and SomaVideoEvent.BUFFERING_COMPLETE event.

Implementation
    public function get bufferLength():Number
bufferPercentageproperty 
bufferPercentage:Number  [read-only]

Get the percentage of the buffer (seconds loaded), the "buffer length" will reach the "buffer time" before playing the video, you can get the information on a SomaVideoEvent.BUFFERING_START, SomaVideoEvent.BUFFERING_PROGRESS and SomaVideoEvent.BUFFERING_COMPLETE event.

Implementation
    public function get bufferPercentage():Number
bufferTimeproperty 
bufferTime:Number  [read-write]

Buffer value in seconds, the default (flash built-in default of the NetStream class) is 0.1 (tenth of a second).

Implementation
    public function get bufferTime():Number
    public function set bufferTime(value:Number):void
bytesLoadedproperty 
bytesLoaded:Number  [read-only]

Get the bytes loaded of the video (preloading), you can get the information on a SomaVideoEvent.PRELOADING_START, SomaVideoEvent.PRELOADING_PROGRESS and SomaVideoEvent.PRELOADING_COMPLETE event.

Implementation
    public function get bytesLoaded():Number
bytesTotalproperty 
bytesTotal:Number  [read-only]

Get the bytes total that the video will preload, you can get the information on a SomaVideoEvent.PRELOADING_START, SomaVideoEvent.PRELOADING_PROGRESS and SomaVideoEvent.PRELOADING_COMPLETE event.

Implementation
    public function get bytesTotal():Number
controlsproperty 
controls:SomaVideoControls  [read-only]

Get the SomaVideoControls instance used to display the controls (play, mute, time bar, and so on).

Implementation
    public function get controls():SomaVideoControls
durationproperty 
duration:Number  [read-only]

Get the time length (seconds) of the video, only available after that an event SomaVideoEvent.METADATA_UPDATE has been dispatched.

Implementation
    public function get duration():Number
fullscreenproperty 
fullscreen:Boolean  [read-write]

State of the fullscreen mode.

Implementation
    public function get fullscreen():Boolean
    public function set fullscreen(value:Boolean):void
fullscreenRectproperty 
fullscreenRect:Rectangle  [read-write]

Rectangle used to display the video in a fullscreen state, the default rectangle is the player itself.

Implementation
    public function get fullscreenRect():Rectangle
    public function set fullscreenRect(value:Rectangle):void
heightproperty 
height:Number  [write-only]

Indicates the height of the SomaVideoPlayer instance, in pixels. This methods is overridden to handle the controls and video resize.

Implementation
    public function set height(value:Number):void
loopproperty 
loop:Boolean  [read-write]

Specifies whether the video will replay on its own when it reaches the end.

Implementation
    public function get loop():Boolean
    public function set loop(value:Boolean):void
panproperty 
pan:Number  [read-write]

Pan (panning) of the video, the range is -1 (for left) to 1 (for right) and the default is 0.

Implementation
    public function get pan():Number
    public function set pan(value:Number):void
preloadingPercentproperty 
preloadingPercent:Number  [read-only]

Get the percentage of the video that is preloaded (0 to 100), you can get the information on a SomaVideoEvent.PRELOADING_START, SomaVideoEvent.PRELOADING_PROGRESS and SomaVideoEvent.PRELOADING_COMPLETE event.

Implementation
    public function get preloadingPercent():Number
smoothingproperty 
smoothing:Boolean  [read-write]

Specifies whether the video should be smoothed (interpolated) when it is scaled.

Implementation
    public function get smoothing():Boolean
    public function set smoothing(value:Boolean):void
timeproperty 
time:Number  [read-only]

Get the current position of the playhead.

Implementation
    public function get time():Number
urlproperty 
url:String  [read-only]

Get the url of the video.

Implementation
    public function get url():String
videoproperty 
video:SomaVideo  [read-only]

Get the SomaVideo instance used to display the video.

Implementation
    public function get video():SomaVideo
videoHeightproperty 
videoHeight:Number  [read-write]

Indicates the height of the video (not the player).

Implementation
    public function get videoHeight():Number
    public function set videoHeight(value:Number):void
videoWidthproperty 
videoWidth:Number  [read-write]

Indicates the width of the video (not the player).

Implementation
    public function get videoWidth():Number
    public function set videoWidth(value:Number):void
volumeproperty 
volume:Number  [read-write]

Volume of the video, the range is 0 to 1 and the default is 1.

Implementation
    public function get volume():Number
    public function set volume(value:Number):void
widthproperty 
width:Number  [write-only]

Indicates the width of the SomaVideoPlayer instance, in pixels. This methods is overridden to handle the controls and video resize.

Implementation
    public function set width(value:Number):void
Constructor detail
SomaVideoPlayer()constructor
public function SomaVideoPlayer(url:String = null, controls:SomaVideoControls = null, autoStart:Boolean = true, loop:Boolean = false)

Create a SomaVideoPlayer instance.

Parameters
url:String (default = null) — A String (url), video that will be played (you can also use the playerInstance.setSource).
 
controls:SomaVideoControls (default = null) — A SomaVideoControlsInstance (an instance with a default skin will be created if you don't pass one in the constructor).
 
autoStart:Boolean (default = true) — Specifies whether the video will start to play once ready.
 
loop:Boolean (default = false) — Specifies whether the video will replay from the beginning at the end of the video.
Method detail
dispose()method
public function dispose():void

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

heightVideoKeepingRatio()method 
public function heightVideoKeepingRatio(value:Number):void

Set the height of the video (not the player), the width will be updated keeping the ratio of the video source. This action can be performed only when the size of the video source is known, in other words, after receiving the metadata information (SomaVideoEvent.METADATA_UPDATE).

_player = new SomaVideoPlayer("video/test.flv");
_player.addEventListener(SomaVideoEvent.METADATA_UPDATE, metadataHandler);
private function metadataHandler(e:SomaVideoEvent):void {
    _player.widthVideoKeepingRatio(100);
}
    

Parameters
value:Number — A Number.
pause()method 
public function pause():void

Pause the video.

play()method 
public function play():void

Play the video.

resume()method 
public function resume():void

Resume the video.

seek()method 
public function seek(time:Number):void

Move the video playhead to a (approximate) time.

Parameters
time:Number — The approximate time value, in seconds, to move to in a video file.
setSource()method 
public function setSource(url:String):void

Set the source to play.

var player:SomaVideoPlayer = new SomaVideoPlayer();
video.setSource("video.flv");
   

Parameters
url:String — A String (URL).
stop()method 
public function stop():void

Stop the video.

widthVideoKeepingRatio()method 
public function widthVideoKeepingRatio(value:Number):void

Set the width of the video (not the player), the height will be updated keeping the ratio of the video source. This action can be performed only when the size of the video source is known, in other words, after receiving the metadata information (SomaVideoEvent.METADATA_UPDATE).

_player = new SomaVideoPlayer("video/test.flv");
_player.addEventListener(SomaVideoEvent.METADATA_UPDATE, metadataHandler);
private function metadataHandler(e:SomaVideoEvent):void {
    _player.widthVideoKeepingRatio(100);
}
    

Parameters
value:Number — A Number.