Tocador de videos em FLV e MP4
To com um probleminha nesse codigo…
Não consigo fazer o load dos arquivos de video que ficam na pasta do swl dentro da função init.
Minha solução está pobre:
Para colocar os vídeos na lista é necessário que eles estejam no mesmo diretório do swf e seleciona-los.
Obs:
O objetivo deste código é que ele seja standalone, por isso não pode ser um AIR.
Neste caso é gerado um swf do qual pelo FlashPlayerDebugger.exe eu o transformo em um EXE.
Quem souber como solucionar isso sem abrir o browser, eu agradeceria muito
Os fontes estão em anexo
Obrigado à quem puder me ajudar
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init()">
<fx:Declarations>
<mx:DateFormatter id="dateFormatter" formatString="NN:SS" />
<mx:Zoom id="zoom" />
<mx:Fade id="fadeIn" alphaFrom="0.0" alphaTo="1.0" />
<mx:Fade id="fadeOut" alphaFrom="1.0" alphaTo="0.0" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.net.FileReference;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.FileReferenceList;
private var fileChooser:FileReferenceList;
private var selectedDirectory:FileReferenceList;
[Bindable] private var ListaFilmes:ArrayCollection;
[Bindable] private var diretoryPath:String = "";
[Bindable] private var filmePath:String;
//=======================================================
//
//=======================================================
private function init():void
{
}
//=======================================================
//
//=======================================================
private function MeuVideo_stop():void
{
if ( MeuVideo.state != "disconnected" )
{
MeuVideo.stop();
testeMovimento = false;
}
}
//=======================================================
//
//=======================================================
private function MeuVideo_PlayPause():void
{
if ( MeuVideo.state != "disconnected" )
{
if (MeuVideo.state == "playing")
{
MeuVideo.pause();
testeMovimento = false;
playPauseButton.label="Play"
//Alert.show(MeuVideo.state );
}
else if (MeuVideo.state == "paused")
{
MeuVideo.play();
playPauseButton.label="Pause"
testeMovimento = true;
//Alert.show(MeuVideo.state );
}
}
}
//=======================================================
//
//=======================================================
private var testeMovimento:Boolean = false;
private function slider_thumbPress():void
{
if ( MeuVideo.state != "disconnected" )
{
MeuVideo.pause();
}
}
//=======================================================
//
//=======================================================
private function slider_thumbRelease():void
{
if ( MeuVideo.state != "disconnected" )
{
MeuVideo.playheadTime = slider.value;
if (testeMovimento == true)
{
MeuVideo.play();
}
else if(testeMovimento == false)
{
MeuVideo.pause();
}
}
}
//=======================================================
//
//=======================================================
private function showControls():void
{
fadeIn.play([controls]);
}
//=======================================================
//
//=======================================================
private function hideControls():void
{
fadeOut.play([controls]);
}
//=======================================================
//
//=======================================================
private function pegarFilmes(event:Event):void
{
selectedDirectory = event.target as FileReferenceList;
//diretoryPath = selectedDirectory.nativePath;
ListaFilmes = new ArrayCollection();
for each( var file:FileReference in selectedDirectory.fileList)
{
var nome:String = file.name;
var extensao:String = nome.toLowerCase().substr(nome.length - 4, 4)
if (extensao == ".flv" || extensao == ".mp4" )
{
ListaFilmes.addItem(nome);
}
}
}
//=======================================================
//
//=======================================================
private function OpenFileChooser():void
{
fileChooser = new FileReferenceList();
fileChooser.addEventListener(Event.SELECT, pegarFilmes);
fileChooser.browse([new FileFilter("Images", "*.flv;*.mp4")]);
}
//=======================================================
//
//=======================================================
private function selecionarFilme(event:MouseEvent):void
{
if (MeuVideo.playing)
{
MeuVideo.stop();
}
filmePath = event.currentTarget.selectedItem;
MeuVideo.play();
testeMovimento == true
playPauseButton.label="Pause"
videoDisplay_playheadUpdate()
}
//=======================================================
//
//=======================================================
private function formatTime(item:Date):String
{
return dateFormatter.format(item);
}
//=======================================================
//
//=======================================================
private function videoDisplay_playheadUpdate():void
{
/* If playhead time is 0, set to 100ms so the DateFormatter doesnt return an empty string. */
var pT:Number = MeuVideo.playheadTime || 0.1;
var tT:Number = MeuVideo.totalTime;
/* Convert playheadTime and totalTime from seconds to milliseconds and create new Date objects. */
var pTimeMS:Date = new Date(pT * 1000);
var tTimeMS:Date = new Date(tT * 1000);
timeLabel.text = formatTime(pTimeMS) + " / " + formatTime(tTimeMS);
}
//=======================================================
//
//=======================================================
private function videoDisplay_ready():void
{
MeuVideo.visible = true;
}
//=======================================================
//
//=======================================================
private function resize():void
{
if (ResizablePanel_2.percentWidth==70)
{
sumir.width = 0;
sumir.visible = false;
ResizablePanel_2.percentWidth = 100 ;
ResizablePanel_1.width = 20;
}
else
{
ResizablePanel_2.percentWidth = 70 ;
ResizablePanel_1.percentWidth = 30 ;
sumir.visible = true;
sumir.percentWidth = 100;
}
}
]]>
</fx:Script>
<s:HGroup width="100%" height="100%" gap="2" paddingTop="2" paddingRight="2" paddingBottom="2" paddingLeft="2">
<s:HGroup id="ResizablePanel_1" gap="0" verticalAlign="middle" width="30%" height="100%" paddingRight="2" >
<s:VGroup id="sumir" width="100%" height="100%" >
<mx:Button id="selecionar" label="Selecionar Pasta" click="OpenFileChooser()" />
<s:List id="Lista" width="100%" height="100%" dataProvider="{ListaFilmes}" click="selecionarFilme(event)" />
</s:VGroup>
<mx:Button click="resize()" width="8" />
</s:HGroup>
<s:VGroup id="ResizablePanel_2"
width="70%" height="100%" >
<mx:Canvas rollOver="showControls()"
rollOut="hideControls()"
width="100%"
height="100%"
>
<mx:VideoDisplay id="MeuVideo" width="100%"
height="100%"
showEffect="{zoom}"
playheadUpdate="videoDisplay_playheadUpdate()"
volume="{Som.value}"
source = "{filmePath}"
/>
<mx:HBox id="controls" alpha="0.0" verticalAlign="bottom" bottom="0" backgroundColor="#FFFFFF" width="100%" >
<mx:Button id="playPauseButton"
toggle="false"
selected="{MeuVideo.playing}"
click="MeuVideo_PlayPause()"
label="Play"
/>
<mx:HSlider id="slider" width="80%"
allowTrackClick="true"
invertThumbDirection="true"
liveDragging="true"
minimum="0"
tickThickness="0"
thumbPress="slider_thumbPress()"
thumbRelease="slider_thumbRelease()"
maximum="{MeuVideo.totalTime}"
value="{MeuVideo.playheadTime}"
/>
<mx:Label id="timeLabel" />
</mx:HBox>
</mx:Canvas>
</s:VGroup>
<mx:VSlider id="Som" height="100%" width="12"
allowTrackClick="true"
invertThumbDirection="true"
liveDragging="true"
minimum="0.0"
maximum="1.0"
value="0.7"
tickThickness="0" />
</s:HGroup>
</s:Application>