Форум Flasher.ru
Ближайшие курсы в Школе RealTime
Список интенсивных курсов: [см.]  
  
Специальные предложения: [см.]  
  
 
Блоги Правила Справка Пользователи Календарь Сообщения за день
 

Вернуться   Форум Flasher.ru > Flash > ActionScript 3.0

Версия для печати  Отправить по электронной почте    « Предыдущая тема | Следующая тема »  
Опции темы Опции просмотра
 
Создать новую тему Ответ
Старый 18.12.2010, 18:46
danleech вне форума Посмотреть профиль Отправить личное сообщение для danleech Найти все сообщения от danleech
  № 1  
Ответить с цитированием
danleech

Регистрация: Dec 2010
Сообщений: 2
По умолчанию Stagevideo зацикливание тормозит

Привет всем!
Вопроса 2:
Можно ли ресайзить stagevideo как захочется не сохраняя aspectratio?
При зацикливании почему-то тормозит. делал по аналогии с обычным. Но в такой связке тормозит и то и другое.

flex sdk 4.5, flash player 10.2, дополнительный параметр компиляции -swf-version=11
подробнее тута:
http://www.adobe.com/devnet/flashpla...age_video.html

Цитата:
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.FullScreenEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.StageVideoAvailabilityEvent;
import flash.events.StageVideoEvent;
import flash.events.TimerEvent;
import flash.events.VideoEvent;
import flash.geom.Rectangle;
import flash.media.SoundTransform;
import flash.media.StageVideo;
import flash.media.StageVideoAvailability;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.system.LoaderContext;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.ui.Keyboard;

/**
*
* @author Thibault Imbert
*
*/
[SWF(frameRate="1", backgroundColor="#000000")]
public class CSimpleStageVideo extends Sprite
{
private static const FILE_NAME:String = "Back30.flv";
private static const INTERVAL:Number = 500;
private static const BORDER:Number = 20;

private var legend:TextField = new TextField();
private var sv:StageVideo;
private var nc:NetConnection;
private var ns:NetStream;
private var customClient:Object;
private var duration: Number;
private var rc:Rectangle;
private var video:Video;
private var thumb:Shape;
private var interactiveThumb:Sprite;
private var totalTime:Number;

private var videoWidth:int;
private var videoHeight:int;
private var outputBuffer:String = new String();
private var rect:Rectangle = new Rectangle(0, 0, 0, BORDER);
private var videoRect:Rectangle = new Rectangle(0, 0, 0, 0);
private var gotStage:Boolean;
private var stageVideoInUse:Boolean;
private var classicVideoInUse:Boolean;
private var accelerationType:String;
private var infos:String = new String();
private var available:Boolean;
private var inited:Boolean;
private var played:Boolean;
private var container:Sprite;

/**
*
*
*/

public function CSimpleStageVideo()
{
// Make sure the app is visible and stage available
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

/**
*
* @param event
*
*/
private function onAddedToStage(event:Event):void
{
// Scaling
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

// Debug infos
legend.autoSize = TextFieldAutoSize.LEFT;
legend.multiline = true;
legend.background = true;
legend.backgroundColor = 0xFFFFFFFF;
addChild(legend);

// Thumb seek Bar
//thumb = new Shape();

//interactiveThumb = new Sprite();
//interactiveThumb.addChild(thumb);
//addChild(interactiveThumb);

// Connections
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
//ns.client = this;
customClient = new Object;
customClient.onMetaData = metaDataHandler;
ns.client = customClient;

// Screen
video = new Video();
video.smoothing = true;

// Video Events
// the StageVideoEvent.STAGE_VIDEO_STATE informs you if StageVideo is available or not
stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, onStageVideoState);
// in case of fallback to Video, we listen to the VideoEvent.RENDER_STATE event to handle resize properly and know about the acceleration mode running
video.addEventListener(VideoEvent.RENDER_STATE, videoStateChange);

// Input Events
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(Event.RESIZE, onResize);
}

private function metaDataHandler( meta:Object ):void
{
duration = meta.duration;
trace("meta duration -> " + duration);
//totalTime = meta.duration;
//stage.addEventListener(Event.ENTER_FRAME, onFrame);
//video.width = stage.stageWidth;// Resize video instance.
//video.height = stage.stageHeight;
//video.x = (stage.stageWidth - video.width) / 2;// Center video instance on Stage.
//video.y = (stage.stageHeight - video.height) / 2;
}

/**
*
* @param event
*
*/
private function onNetStatus(event:NetStatusEvent):void
{
trace(event.info.code);
if ( event.info.code == "NetStream.Play.StreamNotFound" )
legend.text = "Video file passed, not available!";
else if ( event.info.code == "NetStream.Play.Stop" )
{
trace("event on stop");
ns.seek(0);
}
}

/**
*
* @param event
*
*/
private function onKeyDown(event:KeyboardEvent):void
{
if ( event.keyCode == Keyboard.O )
{
if ( available )
// We toggle the StageVideo on and off (fallback to Video and back to StageVideo)
toggleStageVideo(inited=!inited);

} else if ( event.keyCode == Keyboard.F )
{
stage.displayState = StageDisplayState.FULL_SCREEN;
} else if ( event.keyCode == Keyboard.SPACE )
{
ns.togglePause();
}
else if ( event.keyCode == Keyboard.DELETE )
{
ns.seek(0);
}
}

/**
*
* @param width
* @param height
* @return
*
*/
private function getVideoRect(width:uint, height:uint):Rectangle
{
var videoWidth:uint = width;
var videoHeight:uint = height;
var scaling:Number = Math.min ( stage.stageWidth / videoWidth, stage.stageHeight / videoHeight );

videoWidth *= scaling, videoHeight *= scaling;

var posX:uint = stage.stageWidth - videoWidth >> 1;
var posY:uint = stage.stageHeight - videoHeight >> 1;

videoRect.x = 0;
videoRect.y = 0;
videoRect.width = stage.stageWidth;
videoRect.height = stage.stageHeight;

return videoRect;
}

/**
*
*
*/
private function resize ():void
{
if ( stageVideoInUse )
{
// Get the Viewport viewable rectangle
rc = getVideoRect(sv.videoWidth, sv.videoHeight);
// set the StageVideo size using the viewPort property
sv.viewPort = rc;
} else
{
// Get the Viewport viewable rectangle
rc = getVideoRect(video.videoWidth, video.videoHeight);
// Set the Video object size
video.width = rc.width;
video.height = rc.height;
video.x = 0, video.y = 0;
}

//interactiveThumb.x = BORDER, interactiveThumb.y = stage.stageHeight - (BORDER << 1);
legend.text = infos;
}

/**
*
* @param event
*
*/
private function onStageVideoState(event:StageVideoAvailabilityEvent):void
{
// Detect if StageVideo is available and decide what to do in toggleStageVideo
toggleStageVideo(available = inited = (event.availability == StageVideoAvailability.AVAILABLE));
}

/**
*
* @param on
*
*/
private function toggleStageVideo(on:Boolean):void
{
infos = "StageVideo Running (Direct path) : " + on + "\n";

// If we choose StageVideo we attach the NetStream to StageVideo
if (on)
{
stageVideoInUse = true;
if ( sv == null )
{
sv = stage.stageVideos[0];
sv.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);
}
sv.attachNetStream(ns);
if (classicVideoInUse)
{
// If we use StageVideo, we just remove from the display list the Video object to avoid covering the StageVideo object (always in the background)
stage.removeChild ( video );
classicVideoInUse = false;
}
} else
{
// Otherwise we attach it to a Video object
if (stageVideoInUse)
stageVideoInUse = false;
classicVideoInUse = true;
video.attachNetStream(ns);
stage.addChildAt(video, 0);
}

if ( !played )
{
played = true;
ns.play(FILE_NAME);
}
}

/**
*
* @param event
*
*/
private function onResize(event:Event):void
{
resize();
}

/**
*
* @param event
*
*/
private function stageVideoStateChange(event:StageVideoEvent):void
{
infos += "StageVideoEvent received\n";
infos += "Render State : " + event.status + "\n";
resize();
}

/**
*
* @param event
*
*/
private function videoStateChange(event:VideoEvent):void
{
infos += "VideoEvent received\n";
infos += "Render State : " + event.status + "\n";
resize();
}
}
}

Старый 18.12.2010, 23:46
КорДум вне форума Посмотреть профиль Отправить личное сообщение для КорДум Найти все сообщения от КорДум
  № 2  
Ответить с цитированием
КорДум
 
Аватар для КорДум

блогер
Регистрация: Jan 2008
Адрес: syktyvkar
Сообщений: 3,803
Записей в блоге: 10
Уууу, жесть какая. Оформите код другими тегами и табуляций, читать невозможно.
__________________
тут я

Старый 20.12.2010, 01:17
danleech вне форума Посмотреть профиль Отправить личное сообщение для danleech Найти все сообщения от danleech
  № 3  
Ответить с цитированием
danleech

Регистрация: Dec 2010
Сообщений: 2
Код AS3:
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.FullScreenEvent;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.events.NetStatusEvent;
	import flash.events.StageVideoAvailabilityEvent;
	import flash.events.StageVideoEvent;
	import flash.events.TimerEvent;
	import flash.events.VideoEvent;
	import flash.geom.Rectangle;
	import flash.media.SoundTransform;
	import flash.media.StageVideo;
	import flash.media.StageVideoAvailability;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.system.LoaderContext;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.ui.Keyboard;
 
	/**
	 * 
	 * @author Thibault Imbert
	 * 
	 */	
	[SWF(frameRate="1", backgroundColor="#000000")]
	public class CSimpleStageVideo extends Sprite
	{
		private static const FILE_NAME:String = "C:/Users/Dan/Desktop/Goldenbird/render/BackIE.flv";
		private static const INTERVAL:Number = 500;
		private static const BORDER:Number = 20;
 
		private var legend:TextField = new TextField();
		private var sv:StageVideo;
		private var nc:NetConnection;
		private var ns:NetStream;
		private var customClient:Object;
		private var duration: Number;
		private var rc:Rectangle;
		private var video:Video;
		private var thumb:Shape;
		private var interactiveThumb:Sprite;
		private var totalTime:Number;
 
		private var videoWidth:int;
		private var videoHeight:int;
		private var outputBuffer:String = new String();
		private var rect:Rectangle = new Rectangle(0, 0, 0, BORDER);
		private var videoRect:Rectangle = new Rectangle(0, 0, 0, 0);
		private var gotStage:Boolean;
		private var stageVideoInUse:Boolean;
		private var classicVideoInUse:Boolean;
		private var accelerationType:String;
		private var infos:String = new String();
		private var available:Boolean;
		private var inited:Boolean;
		private var played:Boolean;
		private var container:Sprite;
 
		/**
		 * 
		 * 
		 */		 
 
		public function CSimpleStageVideo()
		{
			// Make sure the app is visible and stage available
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
 
		}
 
		/**
		 * 
		 * @param event
		 * 
		 */		
		private function onAddedToStage(event:Event):void
		{
			// Scaling
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
 
			// Debug infos
			legend.autoSize = TextFieldAutoSize.LEFT;
			legend.multiline = true;
			legend.background = true;
			legend.backgroundColor = 0xFFFFFFFF;
			addChild(legend);
 
			// Connections
			nc = new NetConnection();
			nc.connect(null);
			ns = new NetStream(nc);
			ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
			//ns.client = this;
			customClient = new Object;
			customClient.onMetaData = metaDataHandler;
			ns.client = customClient;
 
			// Screen
			video = new Video();
			video.smoothing = true;
 
			// Video Events
			// the StageVideoEvent.STAGE_VIDEO_STATE informs you if StageVideo is available or not
			stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, onStageVideoState);
			// in case of fallback to Video, we listen to the VideoEvent.RENDER_STATE event to handle resize properly and know about the acceleration mode running
			video.addEventListener(VideoEvent.RENDER_STATE, videoStateChange);
 
			// Input Events
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			stage.addEventListener(Event.RESIZE,  onResize);
		}
 
		private function metaDataHandler( meta:Object ):void
		{
			duration = meta.duration;
			trace("meta duration -> " + duration);  
		}
 
		/**
		 * 
		 * @param event
		 * 
		 */		
		private function onNetStatus(event:NetStatusEvent):void
		{
			trace(event.info.code);
			if ( event.info.code == "NetStream.Play.StreamNotFound" )
				legend.text = "Video file passed, not available!";
			else if ( event.info.code == "NetStream.Play.Stop" )
			{
				trace("event on stop");
				ns.seek(0);
			}
		}
 
		/**
		 * 
		 * @param event
		 * 
		 */		
		private function onKeyDown(event:KeyboardEvent):void
		{	
			if ( event.keyCode == Keyboard.O )
			{
				if ( available )
					// We toggle the StageVideo on and off (fallback to Video and back to StageVideo)
					toggleStageVideo(inited=!inited);
 
			} else if ( event.keyCode == Keyboard.F )
			{
				stage.displayState = StageDisplayState.FULL_SCREEN;
			} else if ( event.keyCode == Keyboard.SPACE )
			{
				ns.togglePause();
			}
			else if ( event.keyCode == Keyboard.DELETE )
			{
				ns.seek(0);
			}
		}
 
		/**
		 * 
		 * @param width
		 * @param height
		 * @return 
		 * 
		 */		
		private function getVideoRect(width:uint, height:uint):Rectangle
		{	
			var videoWidth:uint = width;
			var videoHeight:uint = height;
			var scaling:Number = Math.min ( stage.stageWidth / videoWidth, stage.stageHeight / videoHeight );
 
			videoWidth *= scaling, videoHeight *= scaling;
 
			var posX:uint = stage.stageWidth - videoWidth >> 1;
			var posY:uint = stage.stageHeight - videoHeight >> 1;
 
			videoRect.x = 0;
			videoRect.y = 0;
			videoRect.width = stage.stageWidth;
			videoRect.height = stage.stageHeight;
 
			return videoRect;
		}
 
		/**
		 * 
		 * 
		 */		
		private function resize ():void
		{	
			if ( stageVideoInUse )
			{
				// Get the Viewport viewable rectangle
				rc = getVideoRect(sv.videoWidth, sv.videoHeight);
				// set the StageVideo size using the viewPort property
				sv.viewPort = rc;
			} else 
			{
				// Get the Viewport viewable rectangle
				rc = getVideoRect(video.videoWidth, video.videoHeight);
				// Set the Video object size
				video.width = rc.width;
				video.height = rc.height;
				video.x = 0, video.y = 0;
			}
 
			legend.text = infos;
		}
 
		/**
		 * 
		 * @param event
		 * 
		 */		
		private function onStageVideoState(event:StageVideoAvailabilityEvent):void
		{	
			// Detect if StageVideo is available and decide what to do in toggleStageVideo
			toggleStageVideo(available = inited = (event.availability == StageVideoAvailability.AVAILABLE));
		}
 
		/**
		 * 
		 * @param on
		 * 
		 */		
		private function toggleStageVideo(on:Boolean):void
		{	
			infos = "StageVideo Running (Direct path) : " + on + "\n";
 
			// If we choose StageVideo we attach the NetStream to StageVideo
			if (on) 
			{
				stageVideoInUse = true;
				if ( sv == null )
				{
					sv = stage.stageVideos[0];
					sv.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);
				}
				sv.attachNetStream(ns);
				if (classicVideoInUse)
				{
					// If we use StageVideo, we just remove from the display list the Video object to avoid covering the StageVideo object (always in the background)
					stage.removeChild ( video );
					classicVideoInUse = false;
				}
			} else 
			{
				// Otherwise we attach it to a Video object
				if (stageVideoInUse)
					stageVideoInUse = false;
				classicVideoInUse = true;
				video.attachNetStream(ns);
				stage.addChildAt(video, 0);
			}
 
			if ( !played ) 
			{
				played = true;
				ns.play(FILE_NAME);
			}
		} 
 
		/**
		 * 
		 * @param event
		 * 
		 */		
		private function onResize(event:Event):void
		{
			resize();		
		}
 
		/**
		 * 
		 * @param event
		 * 
		 */		
		private function stageVideoStateChange(event:StageVideoEvent):void
		{	
			infos += "StageVideoEvent received\n";
			infos += "Render State : " + event.status + "\n";
			resize();
		}
 
		/**
		 * 
		 * @param event
		 * 
		 */		
		private function videoStateChange(event:VideoEvent):void
		{	
			infos += "VideoEvent received\n";
			infos += "Render State : " + event.status + "\n";
			resize();
		}
	}
}
исправил, надеюсь так понятнее

Создать новую тему Ответ Часовой пояс GMT +4, время: 00:00.
Быстрый переход
  « Предыдущая тема | Следующая тема »  

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.


 


Часовой пояс GMT +4, время: 00:00.


Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.