Menu

[r1761]: / osmf / trunk / apps / samples / plugins / ControlBarPluginSample / src / ControlBarPluginSample.as  Maximize  Restore  History

Download this file

161 lines (134 with data), 6.3 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
/*****************************************************
*
* 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 flash.display.Sprite;
import org.osmf.elements.ParallelElement;
import org.osmf.events.MediaFactoryEvent;
import org.osmf.layout.HorizontalAlign;
import org.osmf.layout.LayoutMetadata;
import org.osmf.layout.VerticalAlign;
import org.osmf.media.*;
import org.osmf.metadata.Metadata;
[SWF(width="640", height="360", backgroundColor="0x000000",frameRate="25")]
public class ControlBarPluginSample extends Sprite
{
public function ControlBarPluginSample()
{
// Construct an OSMFConfiguration helper class:
osmf = new OSMFConfiguration();
// Construct the main element to play back. This will be a
// parallel element, that will hold the main content to
// playback, and the control bar (from a plug-in) as its
// children:
osmf.mediaElement = constructRootElement();
osmf.view = this;
// Add event listeners to the plug-in manager so we'll get
// a heads-up when the control bar plug-in finishes loading:
osmf.factory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD, onPluginLoaded);
osmf.factory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD_ERROR, onPluginLoadError);
// Ask the plug-in manager to load the control bar plug-in:
osmf.factory.loadPlugin(pluginResource);
}
// Internals
//
private var osmf:OSMFConfiguration;
private var rootElement:ParallelElement;
private function onPluginLoaded(event:MediaFactoryEvent):void
{
// The plugin loaded successfully. We can now construct a control
// bar media element, and add it as a child to the root parallel
// element:
rootElement.addChild(constructControlBarElement());
}
private function onPluginLoadError(event:MediaFactoryEvent):void
{
trace("ERROR: the control bar plugin failed to load.");
}
private function constructRootElement():MediaElement
{
// Construct a parallel media element to hold the main content,
// and later on, the control bar.
rootElement = new ParallelElement();
rootElement.addChild(constructVideoElement());
// Use the layout api to set the parallel element's width and
// height. Make it as big as the stage currently is:
var rootElementLayout:LayoutMetadata = new LayoutMetadata();
rootElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, rootElementLayout);
rootElementLayout.width = stage.stageWidth;
rootElementLayout.height = stage.stageHeight;
return rootElement;
}
private function constructVideoElement():MediaElement
{
// Construct a metadata object that we can append to the video's collection
// of metadata. The control bar plug-in will use the metadata to identify
// the video element as its target:
var controlBarTarget:Metadata = new Metadata();
controlBarTarget.addValue(ID, "mainContent");
// Construct a video element:
var video:MediaElement = osmf.factory.createMediaElement(new URLResource(VIDEO_URL));
// Add the metadata to the video's metadata:
video.addMetadata(ControlBarPlugin.NS_CONTROL_BAR_TARGET, controlBarTarget);
return video;
}
private function constructControlBarElement():MediaElement
{
// Construct a metadata object that we'll send to the media factory on
// requesting a control bar element to be instantiated. The factory
// will use it to parameterize the element. Specifically, the ID field
// will tell the plug-in what the ID of the content it should control
// is:
var controlBarSettings:Metadata = new Metadata();
controlBarSettings.addValue(ID, "mainContent");
// Add the metadata to an otherwise empty media resource object:
var resource:MediaResourceBase = new MediaResourceBase();
resource.addMetadataValue(ControlBarPlugin.NS_CONTROL_BAR_SETTINGS, controlBarSettings);
// Request the media factory to construct a control bar element. The
// factory will infer a control bar element is requested by inspecting
// the resource's metadata (and encountering a metadata object of namespace
// NS_CONTROL_BAR_SETTINGS there):
var controlBar:MediaElement = osmf.factory.createMediaElement(resource);
// Set some layout properties on the control bar. Specifically, have it
// appear at the bottom of the parallel element, horizontally centererd:
var layout:LayoutMetadata = controlBar.getMetadata(LayoutMetadata.LAYOUT_NAMESPACE) as LayoutMetadata;
if (layout == null)
{
layout = new LayoutMetadata();
controlBar.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
}
layout.verticalAlign = VerticalAlign.BOTTOM;
layout.horizontalAlign = HorizontalAlign.CENTER;
// Make sure that the element shows over the video: element's with a
// higher order number set are placed higher in the display list:
layout.index = 1;
return controlBar;
}
/* static */
private static const VIDEO_URL:String
= "http://mediapm.edgesuite.net/osmf/content/test/logo_animated.flv";
private static var ID:String = "ID";
// Comment out to load the plug-in for a SWF (instead of using static linking, for testing):
//private static const pluginResource:URLResource = new URLResource("http://mediapm.edgesuite.net/osmf/swf/ControlBarPlugin.swf");
private static const pluginResource:PluginInfoResource = new PluginInfoResource(new ControlBarPlugin().pluginInfo);
}
}
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.