[AS3]as3.0中的flv视频和swf的文件截图示例代码
[AS3]as3.0中的flv视频和swf的文件截图示例代码,要对flv 截图,必面是下载方式,好像rtmp方式我没有试成功
要对flv 截图,必面是下载方式,好像rtmp方式我没有试成功
- package com.heyuansoft.image{
- import com.adobe.images.JPGEncoder;
- import com.adobe.images.BitString;
- import flash.utils.*;
- import flash.display.*;
- import flash.net.*;
- import flash.events.*;
- import flash.utils.ByteArray;
- import fl.video.*;
- public class CatchImageToSwf extends MovieClip{
- private var mc1:MovieClip = new MovieClip();
- private var ldinfo;
- private var flvplay:FLVPlayback = new FLVPlayback();
- public function catchImageToSwf(){
- trace("start......");
- }
- private function trim(myString:String){
- if(myString.indexOf(" ")==-1 && myString.indexOf(" ")==-1){
- return myString;
- }
- var omyString:String=myString;
- myString=replace(myString," "," ");
- var lblanknum:Number=0;
- var rblanknum:Number=0;
- for(var i:Number=0;i<myString.length;i++){
- if(myString.charAt(i)!=" "){
- break;
- }else{
- lblanknum++;
- }
- }
- for(var j:Number=(myString.length-1);j>0;j--){
- if(myString.charAt(j)!=" "){
- break;
- }else{
- rblanknum++;
- }
- }
- return omyString.substring(lblanknum,(omyString.length-rblanknum));
- }
- private function replace(s:String,o:String,n:String){
- return ss=s.split(o).join(n);
- }
- private function getFileName(URLpath:String){
- return URLpath.substring(URLpath.lastIndexOf("/")+1,URLpath.length);
- }
- private function getExpendName(URLpath:String){
- var fileName = getFileName(trim(URLpath));
- if(fileName.indexOf(".")==-1){
- return null;
- }else{
- var temp:String =fileName.substring(fileName.lastIndexOf(".")+1,fileName.length);
- return temp;
- }
- }
- private function getError(e:Event):void{
- trace("error......");
- }
- public function setMc1WidthAndHeight(w:Number,h:Number){
- mc1.width = w;
- mc1.height = h;
- }
- public function setFlvPlayWidthAndHeight(w:Number,h:Number){
- flvplay.width=w;
- flvplay.height=h
- }
- public function getImage(){
- var expendName = getExpendName(url);
- switch(expendName){
- case null:trace("typeError");
- case "flv": playFlv(url,quality,serApp,imageName);break;
- case "swf": playSwf(url,quality,serApp,imageName);break;
- }
- }
- private function playFlv(flvUrl:String,quality:Number,serApp:String,imageName:String):void{
- flvplay.source=flvUrl;
- flvplay.addEventListener("progress",printinfo);
- function printinfo(infoObj:VideoProgressEvent):void{
- if(infoObj.bytesLoaded == flvplay.bytesTotal){
- //这里要注意的就是不须要这么久,
- //可以下载到二分之一处就行,因为我只要在三分之一的地方截图
- trace("source : "+flvplay.bytesTotal);
- trace(Math.floor(flvplay.totalTime/3));
- flvplay.seekSeconds(Math.floor(flvplay.totalTime/3));
- }
- }
- flvplay.addEventListener("seeked",compSeek);
- function compSeek(e:Event){
- trace("seeked");
- createJpg(flvplay,quality,serApp,imageName);
- flvplay.stop();
- }
- }
- private function playSwf(swfUrl:String,quality:Number,serApp:String,imageName:String):void{
- var myVar:int = Math.floor(Math.random()*1000000);
- var url_img:URLRequest = new URLRequest(swfUrl+"?number="+myVar);
- var ld:Loader = new Loader();
- ldldinfo=ld.contentLoaderInfo;
- ldinfo.addEventListener(Event.COMPLETE,getinfo);
- function getinfo(e:Event):void{
- try{
- mc1 =ldinfo.content;
- mc1.gotoAndStop(Math.ceil(mc1.totalFrames/3));
- createJpg(mc1,quality,serApp,imageName);
- }catch(error:TypeError){
- mc1.addChild(ld);
- var minuteTimer:Timer = new Timer(3000, 1);
- minuteTimer.start();
- minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
- function onTick(event:Event):void
- {
- createJpg(mc1,quality,serApp,imageName);
- }
- }
- }
- ldinfo.addEventListener("ioError" ,getError);
- ld.load(url_img);
- }
- private function createJpg(object:DisplayObject,quality:Number,serApp:String,imageName:String):void{
- trace("xxx"+mc1.height);
- if(object.width!=0||object.height!=0){
- var jpgBd:BitmapData = new BitmapData(object.width,object.height);
- jpgBd.draw(object);
- var jpgEncoder:JPGEncoder = new JPGEncoder(quality);
- var jpgStream:ByteArray = jpgEncoder.encode(jpgBd);
- trace("jpgStream:"+jpgStream.length);
- var header:URLRequestHeader = new URLRequestHeader("Content-type","application/octet-stream");
- var url:String =serApp+imageName;
- trace(url);
- var jpgURLRequest:URLRequest = new URLRequest (url);
- jpgURLRequest.requestHeaders.push(header);
- jpgURLRequest.method = URLRequestMethod.POST;
- jpgURLRequest.data = jpgStream;
- //navigateToURL(jpgURLRequest);
- var myLoader:URLLoader = new URLLoader(jpgURLRequest);
- }
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...