/***************************************************** * * Copyright 2009 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) 2009 Adobe Systems * Incorporated. All Rights Reserved. * *****************************************************/ package org.osmf.elements { import org.osmf.elements.compositeClasses.CompositeMetadata; import org.osmf.elements.compositeClasses.CompositionMode; import org.osmf.metadata.Metadata; import org.osmf.traits.MediaTraitBase; /** * ParallelElement is a media composition whose elements are presented * in parallel (concurrently). * *

The media elements that make up a ParallelElement are treated as a * single, unified media element. For example, if a ParallelElement * encapsulates a image and a piece of audio, the ParallelElement will * behave as if it's a single MediaElement with the audio characteristics * of the audio file and the display characteristics of the image file.

* *

Typically, a trait on a ParallelElement is a composite or merged combination * of that trait on all its children. When a new media element is added as a child * of the media composition, either its traits or the composite's traits are adjusted * to make the traits of the media composition and its children consistent.

*

As an example of the first case, consider AudioTrait. * If a client adds a new MediaElement that has its AudioTrait volume at 0.5 * to a ParallelElement that has its AudioTrait volume at 0.3, * the AudioTrait volume for the child MediaElement is set to 0.3 * to be consistent with ParallelElement's trait.

*

As an example of the second case, consider BufferTrait. * If the added MediaElement has a BufferTrait, the ParallelElement's * BufferTrait may need to "grow" if the new MediaElement has a * larger buffer than any of its other children. In this case, the buffer of the * ParallelElement adjusts to the size of its new child. *

* * Here is how each trait is expressed when in parallel: * * * @includeExample ParallelElementExample.as -noswf * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion OSMF 1.0 */ public class ParallelElement extends CompositeElement { /** * Constructor. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion OSMF 1.0 */ public function ParallelElement() { super(); } // Overrides // /** * @private */ override protected function createMetadata():Metadata { var result:Metadata = super.createMetadata(); CompositeMetadata(result).mode = CompositionMode.PARALLEL; return result; } /** * @private */ override protected function processAggregatedTrait(traitType:String, trait:MediaTraitBase):void { super.processAggregatedTrait(traitType, trait); var compositeTrait:MediaTraitBase = getTrait(traitType); // Create the composite trait if it doesn't exist yet. if (compositeTrait == null) { compositeTrait = traitFactory.createTrait ( traitType , traitAggregator , CompositionMode.PARALLEL , this ); if (compositeTrait != null) { addTrait(traitType, compositeTrait); } } } /** * @private */ override protected function processUnaggregatedTrait(traitType:String, trait:MediaTraitBase):void { super.processUnaggregatedTrait(traitType, trait); // Remove the composite trait if the unaggregated trait was the // last child of the composite trait. if (traitAggregator.hasTrait(traitType) == false) { removeTrait(traitType); } } } }