Player de Vídeo em AS2.0 - Primeira Parte
Salve pessoal !
Hoje eu vou dar inicio a uma série de artigos onde vou abordar a construção de um player de vídeo, inicialmente vamos fazer esse player em AS2.0.
Nesse primeiro exercício não vamos usar OOP ( nada de classe ), faremos isso depois de construir todo o player para que todos possam acompanhar como é o processo de desenvolvimento passando por todas as fases.
Características do player desenvolvido:
Toca vídeos no formato FLV.
Indica quando o vídeo está em buffer.
Mostra o tempo total e o tempo de execução do vídeo.
Botão Play e Pause.
Próximas características a serem adicionadas
Controle de som
Modo Fullscreen
Lista de vídeos
Implementação do player em OOP
Feito isso no frame denominado “as” cole o código abaixo.
-
//Importando Delegate
-
import mx.utils.Delegate;
-
//definindo variáveis
-
var conexao:NetConnection;
-
var stream:NetStream;
-
var total:Number;
-
var mcSeek:MovieClip;
-
var tamanho:Number;
-
var txtTempo:TextField;
-
var mcLoad:MovieClip;
-
var btPlay:MovieClip;
-
var videoContainer:Video
-
-
//Configuração do Player
-
function PlayVideo() {
-
-
this.total = 1;
-
this.tamanho = this.mcSeek._width;
-
-
this.conexao = new NetConnection();
-
this.conexao.connect(null);
-
this.stream = new NetStream(this.conexao);
-
this.videoContainer.attachVideo(this.stream);
-
this.stream.play("video.flv");
-
-
this.stream.onMetaData = Delegate.create(this, this.onNsMetaData);
-
this.stream.onStatus = Delegate.create(this, this.onStatusVideo);
-
-
this.stream.setBufferTime(2);
-
this.bufferClip._visible =true
-
-
this.btPlay.gotoAndStop(2)
-
}
-
//Verifica status do Vídeo
-
function onStatusVideo(info:Object){
-
//trace(info.code);
-
if (info.code == "NetStream.Buffer.Full") {
-
bufferClip._visible =false
-
}
-
if (info.code == "NetStream.Buffer.Empty") {
-
stream.seek(0);
-
pauseSincVideo()
-
btPlay.gotoAndStop(1)
-
}
-
if (info.code == "NetStream.Play.Stop") {
-
bufferClip._visible =false
-
}
-
}
-
// Verifica Progresso
-
function onNsMetaData(info:Object) {
-
this.total = info.duration;
-
this.mcSeek.onEnterFrame = this.progressoVideo;
-
}
-
-
//Configura Prograsso
-
function progressoVideo() {
-
txtTempo.text = tempoVideo(stream.time)+" / "+tempoVideo(total);
-
mcSeek._width = tamanho*(stream.time/total);
-
mcLoad._width = tamanho*(stream.bytesLoaded/stream.bytesTotal);
-
}
-
-
//Retorna o tempo total e o tempo
-
//em andamento
-
function tempoVideo(num:Number) {
-
var minimo:Number = Math.floor(num/60);
-
var segundos = Math.floor(num%60);
-
if (segundos<10) {
-
segundos = "0"+segundos;
-
}
-
return minimo+":"+segundos;
-
}
-
-
//Play Vídeo
-
function playSincVideo() {
-
stream.pause(false);
-
btPlay.gotoAndStop(2)
-
}
-
//Pause Video
-
function pauseSincVideo() {
-
stream.pause(true);
-
btPlay.gotoAndStop(1)
-
-
}
-
//Ação do botão PlayPause
-
btPlay.onRelease = function() {
-
if(this._currentframe ==1){
-
_root.playSincVideo();
-
}
-
else{
-
_root.pauseSincVideo();
-
}
-
-
};
-
//Inicia Processo
-
PlayVideo();
Espero que vocês gostem, semana que vem tem a segunda parte do tutorial abraços !
daniel romualdo:
Gostaria de saber para que serve a linha:
stream.seek(0);
dentro do status do stream, após identificar que o status esta empty?
Agradeço.
Posted on julho 18th, 2009 at 4:07 pm
web flv player:
Thanks for given this great post…
Posted on julho 29th, 2009 at 9:52 am