BEML Slow-Motion Control

Written by Bob de Wit. Posted in ActionScript, Brightcove, Developer Blog

This post shows how to create a slow-motion control incorporated into a Brightcove Player using BEML. The full code is listed below.
<!--?xml version="1.0" encoding="utf-8"?-->
<![CDATA[

import mx.controls.Alert;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Stage;
import com.brightcove.api.*;
import com.brightcove.api.components.*;
import com.brightcove.api.dtos.*;
import com.brightcove.api.events.*;
import com.brightcove.api.modules.*;
import com.brightcove.api.search.*;
import com.brightcove.api.utils.*;

private var timer:Timer = new Timer(10);

//Placeholder for BC Player Reference
private var Wrapper:BrightcoveModuleWrapper = null;

//Placeholder for VideoPlayer Reference
private var VideoPlayer:VideoPlayerModule = null;

//Placeholder for Experience Reference
private var Experience:ExperienceModule = null;

private var isFullScreen:Boolean = false;

public function  setInterface(player:IEventDispatcher):void
{
//Save the passed BC player Object reference
Wrapper = new BrightcoveModuleWrapper(player);
Experience = Wrapper.getModule(APIModules.EXPERIENCE) as ExperienceModule;

if (Experience == null)
{
Wrapper.addEventListener(ExperienceEvent.MODULES_LOADED, onModulesLoaded);
Wrapper.loadModules();
}
else
{
checkReady();
}
}

private function onModulesLoaded(event:ExperienceEvent):void
{
Wrapper.removeEventListener(ExperienceEvent.MODULES_LOADED, onModulesLoaded);
Experience = Wrapper.getModule(APIModules.EXPERIENCE) as ExperienceModule;
if (Experience != null)
{
checkReady();
}
}

private function checkReady():void
{
if (Experience.getReady())
{
InitApp();
}
else
{
Experience.addEventListener(ExperienceEvent.TEMPLATE_READY, onTemplateReady);
}
}

private function onTemplateReady(event:ExperienceEvent):void
{
Experience.removeEventListener(ExperienceEvent.TEMPLATE_READY, onTemplateReady);
InitApp();
}

private function InitApp():void
{
timer.addEventListener(TimerEvent.TIMER, onTimer);

VideoPlayer = Wrapper.getModule(APIModules.VIDEO_PLAYER) as VideoPlayerModule;

//Add a listener for full screen switching
Experience.addEventListener(ExperienceEvent.ENTER_FULLSCREEN, onEnterFullScreen);
Experience.addEventListener(ExperienceEvent.EXIT_FULLSCREEN, onExitFullScreen);

//Add a listener for a video being loaded
VideoPlayer.addEventListener(MediaEvent.PROGRESS, onMediaProgress);
VideoPlayer.addEventListener(MediaEvent.CHANGE, onMediaChange)

}

private function onEnterFullScreen(evt:Object):void
{
isFullScreen = true;
}

private function onExitFullScreen(evt:Object):void
{
isFullScreen = false;
}

private function onMediaChange(evt:Object):void
{

}

private function onSlomoChange():void
{
if( slomo.value > 0 )
{
VideoPlayer.setVolume(0);
}
else
{
VideoPlayer.setVolume(1);
}
}

//Handler for videoLoad events from the content module
private function onMediaProgress(evt:MediaEvent):void
{
var time : Number = evt.position;
if( slomo.value > 0 )
{
timer.delay = slomo.value;
VideoPlayer.pause(true);
timer.start();
}
}

private function onTimer(e:Event):void
{
timer.stop();
VideoPlayer.pause(false);
}

private function onMouseOver():void
{

}

private function onPlayClick():void
{
if( ! VideoPlayer.isPlaying() )
{
VideoPlayer.play();

}
else
{
VideoPlayer.pause(true);
}
}

]]>

&nbsp;

Trackback from your site.

Comments (1)

Leave a comment