How to Handle OSMF Metadata and Cuepoints
Posted on October 12, 2013
Open Source Media Framework (OSMF) offers great support for a wide range of media formats, but handling metadata and cue point events is a bit tricky. Because you do not have access to the client object due to encapsulation, you need to create a VideoElement subclass and add listeners. I’ve used LightweightVideoElement because it was the best fit for the job at hand. I don’t see why some other VideoElement object wouldn’t work unless the client has been encapsulated in a superclass.
package ro.stancalau.blog.osmf { import flash.events.Event; import flash.net.URLLoader; import org.osmf.elements.F4MElement; import org.osmf.elements.F4MLoader; import org.osmf.elements.LightweightVideoElement; import org.osmf.elements.LoadFromDocumentElement; import org.osmf.elements.proxyClasses.LoadFromDocumentLoadTrait; import org.osmf.events.LoadEvent; import org.osmf.events.LoaderEvent; import org.osmf.media.MediaElement; import org.osmf.media.MediaResourceBase; import org.osmf.media.URLResource; import org.osmf.net.MulticastNetLoader; import org.osmf.net.NetLoader; import org.osmf.net.NetStreamCodes; import org.osmf.net.NetStreamLoadTrait; import org.osmf.net.httpstreaming.HTTPStreamingNetLoader; import org.osmf.net.rtmpstreaming.RTMPDynamicStreamingNetLoader; import org.osmf.traits.LoadState; import org.osmf.traits.LoadTrait; import org.osmf.traits.LoaderBase; import org.osmf.traits.MediaTraitType; CONFIG::FLASH_10_1 { import flash.events.DRMAuthenticateEvent; import flash.events.DRMErrorEvent; import flash.events.DRMStatusEvent; import flash.net.drm.DRMContentData; import flash.system.SystemUpdaterType; import flash.system.SystemUpdater; import org.osmf.net.drm.NetStreamDRMTrait; import org.osmf.net.httpstreaming.HTTPStreamingNetLoader; } /** * Dispatched when streamMetadata changes. * @eventType META_DATA_CHANGE */ [Event(name="metaDataChanged",type="flash.events.Event")] /** * Dispatched when cuePoint incountered. * @eventType ON_CUE_POINT */ [Event(name="onCuePoint",type="flash.events.Event")] public class CustomLightWeightVideoElement extends LightweightVideoElement { private var _streamMetadata:Object; public static const META_DATA_CHANGE:String = "metaDataChanged"; public static const ON_CUE_POINT:String = "onCuePoint"; public function CustomLightWeightVideoElement(resource:MediaResourceBase=null, loader:NetLoader=null) { super(null, null); super.loader = loader; this.resource = resource; } override protected function processReadyState():void { if (loader==null) { return; } super.processReadyState(); client.addHandler(NetStreamCodes.ON_META_DATA, onMetaData); client.addHandler(NetStreamCodes.ON_CUE_POINT, onCuepoint); } private function onMetaData(info:Object):void { streamMetadata = info; dispatchEvent( new Event(META_DATA_CHANGE)); } private function onCuepoint(info:Object):void { streamMetadata = info; dispatchEvent( new Event(ON_CUE_POINT)); } public function get streamMetadata():Object { return _streamMetadata; } public function set streamMetadata(value:Object):void { _streamMetadata = value; } } }
So… that’s all there is to handling OSMF metadata.
Open Source Media Framework and Flash technologies are outdated and a hassle to run on client machines now in 2020. Consider transitioning to state-of-the-art technologies such as WebRTC for mobile video streaming.
Even now, after more than 15 years, RTMP is still the most reliable and widely used video streaming protocol, a must for professional broadcasts. With the demise of Flash, Flex and Adobe AIR, mobile RTMP SDKs offer the only feasible solution for in-app streaming.
Last update: 17.04.2020
George
February 3, 2014 (12:22)
Thanks for the sample . I have been trying to figure it out for last 5 hours . I checked this sample , I am trying to use it by calling
var myPlayer:CustomLightWeightVideoElement = new CustomLightWeightVideoElement(mediaResource);
but nothing happens . It wont go to trace I have added in constructor . Am I doing it wrong ?
Cristian S.
February 3, 2014 (13:37)
The “override protected function createLoadTrait” should not be there… just erase that. I will update the code as well.