Hey guys,
I'm trying to create a video player app which gets its playlist from an external xml and its going well but I'm getting some serious memory leaks.
Here is my xml playlist:
HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<playlist>
<mp4 label="TestMovie1.mp4" icon="myMovieIcon" />
<mp4 label="TestMovie2.mp4" icon="myMovieIcon" />
<mp4 label="TestMovie3.mp4" icon="myMovieIcon" />
<mp4 label="TestMovie4.mp4" icon="myMovieIcon" />
</playlist>
My main code:
ActionScript Code:
import flash.events.Event;
[Bindable]
public var playlist:String; //"region1"
[Bindable]
public var currentItem:Number = 0;
private var dataXML:XML;
private var contentList:Array = new Array();
private var workDir:String = "c:/temp/";
private function loadXml():void
{
var loader:URLLoader = new URLLoader(new URLRequest(workDir + playlist + ".xml"));
loader.addEventListener("complete", parseXml);
}
private function parseXml(e:Event):void
{
dataXML = XML(e.target.data);
var listLength:Number = dataXML.children().length();
for(var i:Number = 0; i<listLength; i++)
{
contentList.push(dataXML.children()[i]..@label);
}
nextItem();
}
private function nextItem():void
{
var dataFile:File = new File(workDir + contentList[currentItem]);
if(dataFile.exists)
{
if(dataFile.extension == "mp4" || dataFile.extension == "flv")
{
var vp:videoPlayer = new videoPlayer();
this.addElement(vp);
vp.addEventListener(Event.COMPLETE, movieDone);
vp.x = 0;
vp.y = 0;
vp.width = this.width;
vp.height = this.height;
vp.vidName = workDir + contentList[currentItem];
vp.vidWidth = vp.width;
vp.vidHeight = vp.height;
vp.vidDis.scaleMode = "letterbox";
}
}
else
{
trace(contentList[currentItem] + " can't be located");
}
}
public function movieDone(e:Event):void
{
this.removeAllElements();
if(currentItem == contentList.length -1)
{
currentItem = 0;
nextItem();
}
else
{
currentItem = currentItem + 1;
nextItem();
}
}
And the videoPlayer component:
Code:
<s:Group>
<fx:Metadata>
[Event(name="complete", type="flash.events.Event")]
</fx:Metadata>
<fx:Script>
<![CDATA[
ActionScript Code:
import org.osmf.events.TimeEvent;
[Bindable]
public var vidName:String;
[Bindable]
public var vidWidth:Number;
[Bindable]
public var vidHeight:Number;
protected function videoplayer1_completeHandler(event:TimeEvent):void
{
var e:Event = new Event("complete");
dispatchEvent(e);
}
]]>
</fx:Script>
<mx:Container x="0" y="0" width="{vidWidth}" height="{vidHeight}" backgroundColor="#000000">
<s:VideoDisplay id="vidDis" x="0" y="0" width="{vidWidth}" height="{vidHeight}" source="{vidName}" complete="videoplayer1_completeHandler(event)" chromeColor="#000000"/>
</mx:Container>
</s:Group>
So I create the videoPlayer component and pass in the mp4 file from an array. Once the video is complete it dispatches a custom event which runs the movieDone function. I call the this.removeAllElements() to remove the videoPlayer component before adding it again. I am very new at this but it doesnt seem like the video is being removed as the physical memory climbs with each new video, and eventually after several loops the program will crash. Anyone know what I'm doing wrong?