在播放Flv视频时添加标题或边框(1)

使用ActionScript3叠加图形为FLV视频添加标题和边框
这篇博客介绍了如何在播放FLV视频时添加标题和边框。作者在找不到相关Demo或Example的情况下,通过研究帮助文档和ActionScript3.0 CookBook,发现可以利用可视对象列表的叠加来实现这一功能。首先展示了实现图形叠加的代码,包括Edit.mxml、EditHandle.as和CircleExample.as三个部分。接下来的计划是创建一个通用的处理效果类,以便在主程序中轻松添加标题、边框等效果,并在效果类中处理图形的文字、颜色、大小等编辑操作。

 刚看到这个要求时,虽然实现后的效果并不是多么炫,不过要实现这些简单的效果却真的让我有些茫然无措,用Google搜索了N久也没有看到一篇能够使用的Demo或Example,无奈之下只好从最基本也是最全面的资料--帮助文档分析起了,同时借鉴于ActionScritp3.0 CookBook的莫大帮助,才发现原来可以通过可视对象列表的叠加来实现,一点一点的磨损最终算是将一个很Ugly的图形放在了视频上,先把code粘到这,下一步的添加标题或边框应该就没有问题了。

Edit.mxml:(通过btnLoad按钮来添加叠放图形)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    
<mx:Panel x="10" y="10" width="403" height="385" layout="absolute">
        
<mx:VideoDisplay x="10" y="10" width="363" height="275" id="player" source="video/2.flv" autoPlay="false" borderColor="#0000ff" borderStyle="solid"/>
        
<mx:Button x="202" y="313" label="Play" id="btnPlay" click="player.play();"/>
        
<mx:Button x="286" y="313" label="Stop" id="btnStop" click="player.stop();"/>
        
<mx:Button x="105" y="313" label="Load" id="btnLoad" click="drawRect();"/>
    
</mx:Panel>
    
    
<mx:Script source="EditHandle.as"/>
    
<mx:Panel x="421" y="10" width="250" height="124" layout="absolute">
        
<mx:Button x="10" y="10" label="Merge" id="btnMer"/>
    
</mx:Panel>
</mx:Application>

EditHandle.as:(Edit.mxml的脚本处理文件,只有其中的drawRect函数起作用,即绘制图形)

// ActionScript file
import mx.controls.VideoDisplay;
import mx.controls.videoClasses.CuePointManager;
import flash.text.TextField;
import snow.CircleExample;

private function displayCuePoint():void
{
    
//var proxy:CuePointManager=new CuePointManager(player.cuePointManager);
    var cuePoints:Array=player.cuePoints;
    trace(
"as");
    
for(var o:Object in cuePoints)
    {
        trace(o.name
+":"+o.time);
    }
}

//Did not function!
private function drawRect():void
{
    
//player.drawRoundRect(20,20,20,20,4,0xFF0000);
    var obj:CircleExample=new CircleExample();
    player.addChild(obj);
}

private function drawText():void
{
    var field:TextField
=new TextField();
    field.text
="Hello,I'm out!";
    field.textColor
=0xFF0000;
    field.embedFonts
=true;
    field.x
=30;
    field.y
=30;
    player.addChild(field);
    
//DisplayObjectContainer(root).addChild(field);
    
//trace(root);
}

CircleExample.as:(绘制图形的类)

package snow
{
    import flash.display.Sprite;
    import flash.display.Shape;

    
public class CircleExample extends Sprite
    {
        
public function CircleExample(  ) 
        {
          
// Create three different colored circles and
          
// change their coordinates so they are staggered
          
// and aren't all located at (0,0).
          var red:Shape = createCircle( 0xFF000010 );
          red.x 
= 10;
          red.y 
= 20;
          var green:Shape 
= createCircle( 0x00FF0010 );
          green.x 
= 15;
          green.y 
= 25;
          var blue:Shape 
= createCircle( 0x0000FF10 );
          blue.x 
= 20;
          blue.y 
= 20;
          
          
// First add the red circle, then add the blue circle (so blue 
          
// is drawn on top of red)
          addChild( red );
          addChild( blue );
          
          
// Place the green circle between the red and blue circles
          addChildAt( green, 1 );
        }
        
        
// Helper function to create a circle shape with a given color
        
// and radius
        public function createCircle( color:uint, radius:Number ):Shape 
        {
          var shape:Shape 
= new Shape(  );
          shape.graphics.beginFill( color );
          shape.graphics.drawCircle( 
00, radius );
          shape.graphics.endFill(  );
          
return shape;
        }
      }
        
}

花了一下午的时间总算是有点收获,下来要做的事就是写一个通用的处理添加效果的类,这样在主程序中只需要将其对象通过addChild或addChildAt添加到VideoDisplay中即可。而对于对所添加对象的编辑,如文字字体,颜色,大小,方向等的设置,图象的大小,位置等的设置,都放在效果类中处理即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值