﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.mattiasnorell.com &#187; brightcove</title>
	<atom:link href="http://blog.mattiasnorell.com/tag/brightcove/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mattiasnorell.com</link>
	<description>Otukt i otakt</description>
	<lastBuildDate>Tue, 07 Feb 2012 22:58:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Brightcove plugin, custom mutebutton</title>
		<link>http://blog.mattiasnorell.com/2009/12/17/brightcove-plugin-custom-mutebutton/</link>
		<comments>http://blog.mattiasnorell.com/2009/12/17/brightcove-plugin-custom-mutebutton/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 21:02:07 +0000</pubDate>
		<dc:creator>Mattias</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[In english]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[brightcove]]></category>
		<category><![CDATA[flashdevelop]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blog.mattiasnorell.com/?p=257</guid>
		<description><![CDATA[I think Brightcove is a great service. I&#8217;ve been building videoplayers using their API for the past months and I must say it&#8217;s super sweet. The API take a while to get your head around but once you do you &#8230; <a href="http://blog.mattiasnorell.com/2009/12/17/brightcove-plugin-custom-mutebutton/">Läs mer <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I think <a href="http://www.brightcove.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.brightcove.com?referer=');">Brightcove</a> is a great service. I&#8217;ve been building videoplayers using their API for the past months and I must say it&#8217;s super sweet. The API take a while to get your head around but once you do you can do a lot, even if you are just using their own markup-language BEML (Brightcove Experience Markup Language).</p>
<p>But this is&#8217;nt a post about how great Brightcove is. I know by experience that you can find a lot of stuff on the internet but not that many tutorials about Brightcoveplayers and that is a problem if you are just getting started and need a push in the right direction.</p>
<h3>Before I start.</h3>
<p>I do assume that you have used the Brightcove Studio, you know how to create playertemplates using BEML and know some basic ActionScript 3.</p>
<h3>Some background.</h3>
<p>The client I&#8217;ve done most of my Brightcoveprojects for wanted a chromeless player with nothing more than a mutebutton. They didn&#8217;t want to use the default controllers so I needed to write a custom plugin. Doing so is pretty straight forward but if you know a thing or two about the Player API you might understand how things work a little more.</p>
<h3>It all began in&#8230; the template</h3>
<p>The first thing you need to do is <a href="#" target="_blank">download the API SWC from Brightcove</a>.</p>
<p>Then you need to create a playertemplate inside the Brightcove studio. The player on which I based this tutorial got no controls beside the &#8221;play&#8221;-button that appear when you click on the moviearea.</p>
<p>A Brightcove plugins is nothing more than a SWF that you tell the template to import using the SWFLoader. So in the template we add a VideoPlayer-object and a SWFLoader-object. Since we use a VideoPlayer-object we can&#8217;t add a playlist to the player and therefore we don&#8217;t need to tell it which playlist or video to play since it will get that ID thru the embedcode. Moving on to the SWFLoader. The most important thing is the source, here you tell the template from where you want to load the plugin. Then set the X and Y-position of the plugin to what ever you want.</p>
<p>And that is pretty much all we have to do inside the Brightcove Studio. The last thing you need to do is to create the player itself and enable the &#8221;Enable ActionScript/JavaScript APIs&#8221;-option otherwise you will bash your head bloody against the screen since nothing you do will work.</p>
<pre class="brush: xml; font-size: 50%">&lt;Runtime&gt;
&lt;Layout style="background-color:#000000" width="600" height="200"&gt;
&lt;VideoDisplay id="videoPlayer"/&gt;
&lt;SWFLoader depth="2" y="10" x="10" source="YOUR_DOMAIN_URL_HERE/swfname.swf"/&gt;
&lt;/Layout&gt;
&lt;/Runtime&gt;</pre>
<h3>The plugin</h3>
<p>When I code I use FlashDevelop or Flex Builder. As long as the IDE you use can import SWC-files your safe, if not i suggest you download the free IDE <a href="http://www.flashdevelop.org" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.flashdevelop.org?referer=');">FlashDevelop</a> and the <a href="http://www.adobe.com/products/flex/flexdownloads/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.adobe.com/products/flex/flexdownloads/?referer=');">Flex SDK</a>.</p>
<p>Fire up your IDE and create a new project. The only thing that matters is that you use AS3. Now include the Player API SWC in the project and we can start to write some code. *jay* You can read more about SWCs <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_30.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/livedocs.adobe.com/flex/3/html/help.html?content=compilers_30.html&amp;referer=');">here</a> and how to include them into your FlashDevelop-project <a href="http://www.flashdevelop.org/community/viewtopic.php?p=22197#p22197" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.flashdevelop.org/community/viewtopic.php?p=22197_p22197&amp;referer=');">here</a>.</p>
<p>When I write plugins I do it in two different ways. The first one is to hook the VideoPlayer-module yourself. That requires you to write a lot of extra code but saves you a few kb in the end and gives you more control. The other way is to let your mainclass extend the CostumeModule. The CostumModule-class will take care of all the API-stuff at the cost of a few extra kb but in the end it will save you some work. It&#8217;s all comes down to if you want to re-invent the wheel or not.</p>
<p>Since I wanted the mutebutton to have an on and off-state I created two MovieClips with the classname &#8221;muteOn&#8221; and &#8221;muteOff&#8221; in Flash, exported the graphics as a SWC and included it in my FlashDevelop-project.</p>
<p>We begin by importing everything we need. The Sprite and MouseEvent are standard AS3-stuff so nothing new there so we move on to the three Brightcove-classes. <a href="http://docs.brightcove.com/en/player/com/brightcove/api/modules/APIModule.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/docs.brightcove.com/en/player/com/brightcove/api/modules/APIModule.html?referer=');">APIModules</a>, <a href="http://docs.brightcove.com/en/player/com/brightcove/api/CustomModule.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/docs.brightcove.com/en/player/com/brightcove/api/CustomModule.html?referer=');">CustomModule</a> and <a href="http://docs.brightcove.com/en/player/com/brightcove/api/modules/VideoPlayerModule.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/docs.brightcove.com/en/player/com/brightcove/api/modules/VideoPlayerModule.html?referer=');">VideoPlayerModule</a>. If you want more in depth knowledge about what they do just follow the links. Now we create all the stuff we want to use. The only thing that might be new is the datatype for the _playerModule, VideoPlayerModule. This will allow us to use all the stuff the videoplayer can, like mute, but before we can do that we must link _playerModule and the actual videoplayer together. We do that by overriding the initialize-function in the CostumModule-class, or at least I think it&#8217;s in that class. But it works.</p>
<p>In the Main-function we set up the graphics and the mouseevent. The variable muted is just to keep track of whether the player is muted or not. You might be able to ask the videoplayer if it&#8217;s muted or not, it&#8217;s not pretty but for this plugin I think this solution does the job.</p>
<p>When the user click the button the MouseEvent will call the mute-function and set the visibility for both icons to false and then let the if-statement check whether the player is muted. If not, the visibility of &#8221;muteOnGfx&#8221; is set to true and the mute-function within the videoplayer-object fires. When we call the mute-function we have to pass a booelan parameter, True if we want the sound off and false if we want it on. And that is it. Mute away now kids!</p>
<h3>The code in one piece</h3>
<pre class="brush: actionscript3; font-size: 50%">package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import com.brightcove.api.APIModules;
import com.brightcove.api.CustomModule;
import com.brightcove.api.modules.VideoPlayerModule;

public class Main extends CustomModule{
private var button:Sprite = new Sprite();
private var _playerModule:VideoPlayerModule;
private var muted:Boolean = false;
private var muteOnGfx:muteOn = new muteOn();
private var muteOffGfx:muteOff = new muteOff();

override protected function initialize():void {
_playerModule = player.getModule(APIModules.VIDEO_PLAYER) as VideoPlayerModule;
}

public function Main():void {
button.addChild(muteOnGfx);
button.addChild(muteOffGfx);

if (muted == false) {
muteOnGfx.visible = false;
}else {
muteOffGfx.visible = false;
}

button.buttonMode = true;
addChild(button);

button.addEventListener(MouseEvent.CLICK, mute);
}

private function mute(e:MouseEvent):void {
muteOnGfx.visible = false;
muteOffGfx.visible = false;

if (muted == false) {
_playerModule.mute(true);
muteOnGfx.visible = true;
muted = true;
}else {
_playerModule.mute(false);
muteOffGfx.visible = true;
muted = false;
}
}
}
}</pre>
<h3>Conclusion</h3>
<p>This plugin could of course be modified to control almost everything like play-, pause-, stopbuttons etc. But this is a start and I plan to write some more tutorials about how to make the Brightcoveplayer do what you want. The first step is the hardest, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattiasnorell.com/2009/12/17/brightcove-plugin-custom-mutebutton/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

