Menu

[r1148]: / osmf / trunk / apps / samples / plugins / ControlBarPlugin / src / ControlBarElement.as  Maximize  Restore  History

Download this file

192 lines (160 with data), 6.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*****************************************************
*
* Copyright 2010 Adobe Systems Incorporated. All Rights Reserved.
*
*****************************************************
* 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 Initial Developer of the Original Code is Adobe Systems Incorporated.
* Portions created by Adobe Systems Incorporated are Copyright (C) 2010 Adobe Systems
* Incorporated. All Rights Reserved.
*
*****************************************************/
package
{
import org.osmf.chrome.controlbar.ControlBarBase;
import org.osmf.chrome.controlbar.ControlBarWidget;
import org.osmf.chrome.controlbar.Direction;
import org.osmf.chrome.controlbar.widgets.*;
import org.osmf.layout.LayoutRendererProperties;
import org.osmf.media.MediaElement;
import org.osmf.media.MediaResourceBase;
import org.osmf.metadata.IMetadataProvider;
import org.osmf.metadata.Facet;
import org.osmf.metadata.FacetKey;
import org.osmf.traits.DisplayObjectTrait;
import org.osmf.traits.MediaTraitType;
public class ControlBarElement extends MediaElement
{
public function addReference(target:MediaElement):void
{
if (this.target == null)
{
this.target = target;
processTarget();
}
}
private function processTarget():void
{
if (target != null && settings != null)
{
// We use the NS_CONTROL_BAR_TARGET namespaced metadata facet in order
// to find out if the instantiated element is the element that our
// control bar should control:
var targetFacet:Facet = getTargetFacet(target);
if (targetFacet)
{
if ( targetFacet.getValue(ID) != null
&& targetFacet.getValue(ID) == settings.getValue(ID)
)
{
controlBar.element = target;
}
}
}
}
// Overrides
//
override public function set resource(value:MediaResourceBase):void
{
// Right after the media factory has instantiated us, it will set the
// resource that it used to do so. We look the NS_CONTROL_BAR_SETTINGS
// namespaced metadata facets, and retain it as our settings record
// (containing only one field: "ID" that tells us the ID of the media
// element that we should be controlling):
if (value != null)
{
settings
= value.metadata.getFacet(ControlBarPlugin.NS_CONTROL_BAR_SETTINGS);
processTarget();
}
super.resource = value;
}
override protected function setupTraits():void
{
// Setup a control bar using the ChromeLibrary:
setupControlBar();
// Signal that this media element is viewable: create a DisplayObjectTrait.
// Assign controlBar (which is a Sprite) to be our view's displayObject.
// Additionally, use its current width and height for the trait's mediaWidth
// and mediaHeight properties:
viewable = new DisplayObjectTrait(controlBar, controlBar.measuredWidth, controlBar.measuredHeight);
// Add the trait:
addTrait(MediaTraitType.DISPLAY_OBJECT, viewable);
// Set the control bar's width and height as absolute layout values:
var layoutProperties:LayoutRendererProperties = new LayoutRendererProperties(this);
layoutProperties.width = controlBar.measuredWidth;
layoutProperties.height = controlBar.measuredHeight;
super.setupTraits();
}
// Internals
//
private function getTargetFacet(target:IMetadataProvider):Facet
{
var targetFacet:Facet;
if (target)
{
targetFacet
= target.metadata.getFacet(ControlBarPlugin.NS_CONTROL_BAR_TARGET);
}
return targetFacet;
}
private function setupControlBar():void
{
controlBar = new ControlBarBase();
var widget:ControlBarWidget;
widget = controlBar.addWidget(SCRUB_BAR, new ScrubBar());
widget.setPosition(0, SCRUBBAR_VERTICAL_OFFSET);
widget = controlBar.addWidget(PLAY_BUTTON, new PlayButton());
widget.setPosition(BORDER_SPACE, BUTTONS_VERTICAL_OFFSET);
widget = controlBar.addWidget(PAUSE_BUTTON, new PauseButton());
widget.setRegistrationTarget(PLAY_BUTTON, Direction.RIGHT);
widget.setPosition(1, 0);
widget = controlBar.addWidget(QUALITY_BUTTON, new QualityModeToggle());
widget.setRegistrationTarget(PAUSE_BUTTON, Direction.RIGHT);
widget.setPosition(3, 0);
widget.hint = "Click to toggle between automatic and manual quality mode";
widget = controlBar.addWidget(QUALITY_INCREASE, new QualityIncreaseButton());
widget.setRegistrationTarget(QUALITY_BUTTON, Direction.RIGHT);
widget.setPosition(-2, 4);
widget = controlBar.addWidget(QUALITY_DECREASE, new QualityDecreaseButton());
widget.setRegistrationTarget(QUALITY_INCREASE, Direction.RIGHT);
widget.setPosition(1, 0);
widget = controlBar.addWidget(QUALITY_LABEL, new QualityLabel());
widget.setRegistrationTarget(QUALITY_DECREASE, Direction.RIGHT);
widget.setPosition(0, -3);
widget = controlBar.addWidget(SOUND_MORE, new SoundMoreButton());
widget.setPosition(292, BUTTONS_VERTICAL_OFFSET);
widget = controlBar.addWidget(SOUND_LESS, new SoundLessButton());
widget.setRegistrationTarget(SOUND_MORE, Direction.LEFT);
widget.setPosition(1, 0);
}
private var settings:Facet;
private var target:MediaElement;
private var controlBar:ControlBarBase;
private var viewable:DisplayObjectTrait;
/* static */
private static const ID:FacetKey = new FacetKey("ID");
private static const SCRUB_BAR:String = "scrubBar";
private static const PAUSE_BUTTON:String = "pauseButton";
private static const PLAY_BUTTON:String = "playButton";
private static const QUALITY_BUTTON:String = "qualityButton";
private static const QUALITY_INCREASE:String = "qualityIncrease";
private static const QUALITY_DECREASE:String = "qualityDecrease";
private static const QUALITY_LABEL:String = "qualityLabel";
private static const SOUND_LESS:String = "soundLess";
private static const SOUND_MORE:String = "soundMore";
private static const BUTTONS_VERTICAL_OFFSET:Number = 10;
private static const SCRUBBAR_VERTICAL_OFFSET:Number = 22;
private static const BORDER_SPACE:Number = 9;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.