Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtitiles in Flash using XML?

Status
Not open for further replies.
Simply put, it is broken down into:
1. Read and parse XML cue points data
2. Add cue points to the FLV using FLVPlayback.addASCuePoint()
3. Do something with cue points on FLV playback

The step 1 is not directly related to FLV cue point, you can skip it and use hard-coded cue point data for the sake of exercise if you wish.

Which bit you don't understand?


Kenneth Kawamoto
 
Hi
Thanks for the response:

I understand that i know i must make a .XML file with cuepoints in, plus i know how to do it.

But i dont understand how to fit the .XML file into the .FLV movie.

Please help me

Thanks, Fredd1
 
Im unfortunatly very very bad in XML. Im sorry this may be to boring for you to help me with. I really dont undestand it =(

 
OK, here's the script I wrote very quickly.

Let's start with the XML - "cuepoints.xml":
Code:
<?xml version="1.0"?>
<cuepoints>
	<cuepoint>
		<time>1</time>
		<name>cue1</name>
	</cuepoint>
	<cuepoint>
		<time>2</time>
		<name>cue2</name>
	</cuepoint>
	<cuepoint>
		<time>3.5</time>
		<name>cue3</name>
	</cuepoint>
</cuepoints>
This XML describes 3 cuepoints. "cue1" is at 1 second, "cue2" is at 2 seconds, and "cue3" is at 3-and-a-half seconds.

You want to add these cuepoints to the FLV on the fly.

The stratergy would be:
[ol]
[li]Create the FLVPlayBack Component and set the content path to the external FLV[/li]
[li]Set up the listener so that when a cuepoint is reached it outputs the cuepoint info (in the real situation you would set up some function to do something when a cuepoint is reached)[/li]
[li]When FLV is ready, load the XML[/li]
[li]On each cuepoint node in the XML add the cuepoint to the FLV[/li]
[li]When XML is done start the FLV[/li]
[/ol]
What you will need is the FLVPlayBack Component in the Library, the external XML and the FLV ("video.flv" in this example). The following script goes to the first frame of the main timeline. Nothing on Stage.
Code:
import mx.video.*;
var flv:FLVPlayback = this.attachMovie("FLVPlayback", "flv", 1);
var lo:Object = new Object();
lo.ready = function(evt:Object):Void  {
	loadCuePoints();
};
flv.addEventListener("ready",lo);
lo.cuePoint = function(evt:Object):Void  {
	for (var s in evt.info) {
		trace(s+": "+evt.info[s]);
	}
	trace("***");
};
flv.addEventListener("cuePoint",lo);
with (flv) {
	autoPlay = false;
	contentPath = "video.flv";
}
function loadCuePoints():Void {
	var xmlObj:XML = new XML();
	xmlObj.ignoreWhite = true;
	xmlObj.onLoad = function(OK:Boolean):Void  {
		if (OK) {
			addCuePoints(this);
		} else {
			trace("XML load failed");
		}
	};
	xmlObj.load("cuepoints.xml");
}
function addCuePoints(xmlObj):Void {
	var cuepoints:XMLNode = xmlObj.firstChild;
	for (var i = 0, n = cuepoints.childNodes.length; i<n; i++) {
		var cuepoint:XMLNode = cuepoints.childNodes[i];
		var cuepointObj:Object = new Object();
		for (var j = 0; j<2; j++) {
			var cuepointElement:XMLNode = cuepoint.childNodes[j];
			switch (cuepointElement.nodeName) {
				case "name" :
					cuepointObj["name"] = cuepointElement.firstChild.nodeValue;
					break;
				case "time" :
					cuepointObj["time"] = parseFloat(cuepointElement.firstChild.nodeValue);
					break;
			}
		}
		flv.addASCuePoint(cuepointObj);
	}
	startFLV();
}
function startFLV():Void {
	flv.play();
}
It will output at the each cuepoint on specified time:
Code:
name: cue1
time: 1
type: actionscript
***
name: cue2
time: 2
type: actionscript
***
name: cue3
time: 3.5
type: actionscript
***

Kenneth Kawamoto
 
wow thanks m8 i've have a look at it =D.

BTW you are Awsome!

fredd1
 
So i did make a folder with the .flv in, the cuepoints.xml but what format should the "FLVPlayBack" be in. .XML dosent work...

 
Ok now i've made the .fla file by:

new text document, paste the code into and rename extension.

so whats next???

BTW i was in summerhouse, so i coulds't response.

Thanks, Fredd1
 
ok what flash? and how?

im programming in java plus so i dont know anything anout flash.

please link med the flash thing.

and tell me how

thanks, Fredd1
 
i have a better idea...

can u send me the needed files instead

put it on filebeam, i dont wanna say my email at a public forum.

Fredd1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top