| Package | com.soma.view.video |
| Class | public class SomaVideoPlayer |
| Inheritance | SomaVideoPlayer 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
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);
var controls:SomaVideoControls = new SomaVideoControls();
controls.addControl(new SomaVideoMuteSkin());
controls.addControl(new SomaVideoTimeBarSkin());
var player:SomaVideoPlayer = new SomaVideoPlayer("video/video.flv", controls);
addChild(player);
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);
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);
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 also
| Property | Defined 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 | ||
| Method | Defined 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 | ||
| autoStart | property |
autoStart:Boolean [read-only]Specifies whether the video will automatically start playing once ready.
Implementation public function get autoStart():Boolean
| bufferLength | property |
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
| bufferPercentage | property |
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
| bufferTime | property |
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
| bytesLoaded | property |
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
| bytesTotal | property |
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
| controls | property |
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
| duration | property |
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
| fullscreen | property |
fullscreen:Boolean [read-write]State of the fullscreen mode.
Implementation public function get fullscreen():Boolean
public function set fullscreen(value:Boolean):void
| fullscreenRect | property |
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
| height | property |
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
| loop | property |
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
| pan | property |
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
| preloadingPercent | property |
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
| smoothing | property |
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
| time | property |
time:Number [read-only]Get the current position of the playhead.
Implementation public function get time():Number
| url | property |
url:String [read-only]Get the url of the video.
Implementation public function get url():String
| video | property |
video:SomaVideo [read-only]Get the SomaVideo instance used to display the video.
Implementation public function get video():SomaVideo
| videoHeight | property |
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
| videoWidth | property |
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
| volume | property |
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
| width | property |
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
| SomaVideoPlayer | () | constructor |
public function SomaVideoPlayer(url:String = null, controls:SomaVideoControls = null, autoStart:Boolean = true, loop:Boolean = false)Create a SomaVideoPlayer instance.
Parametersurl: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.
|
| dispose | () | method |
public function dispose():voidCall 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):voidSet 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);
}
value:Number — A Number.
|
| pause | () | method |
public function pause():voidPause the video.
| play | () | method |
public function play():voidPlay the video.
| resume | () | method |
public function resume():voidResume the video.
| seek | () | method |
public function seek(time:Number):voidMove the video playhead to a (approximate) time.
Parameterstime:Number — The approximate time value, in seconds, to move to in a video file.
|
| setSource | () | method |
public function setSource(url:String):voidSet the source to play.
var player:SomaVideoPlayer = new SomaVideoPlayer();
video.setSource("video.flv");
url:String — A String (URL).
|
| stop | () | method |
public function stop():voidStop the video.
| widthVideoKeepingRatio | () | method |
public function widthVideoKeepingRatio(value:Number):voidSet 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);
}
value:Number — A Number.
|