• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 961
  • Last Modified:

cue points in flvplayback: sycronising video and text

I have a video that I'm playing in Flash using flvplayback and I need text to appear over the top of the video. The text fades in, stays for a while then fades out. At the moment I have my text animated on a timeline in a movieclip and placed on the stage. There is a stop action on the first frame of the movieclips containing the text animations and I have the following script to trigger the text off:

import fl.video.FLVPlayback;
import fl.video.MetadataEvent;

flvPlayBack.source = "video.flv";
flvPlayBack.addASCuePoint (0.1, "cue2");//add AS cue point
flvPlayBack.addEventListener (MetadataEvent.CUE_POINT, cp_listener2);
function cp_listener2 (ev:MetadataEvent):void
{
    if (ev.info.name == "cue2")
    {
            why_magee.gotoAndPlay(2);
    }
}

flvPlayBack.source = "video.flv";
flvPlayBack.addASCuePoint (14, "cue3");//add AS cue point
flvPlayBack.addEventListener (MetadataEvent.CUE_POINT, cp_listener3);
function cp_listener3 (ev:MetadataEvent):void
{
    if (ev.info.name == "cue3")
    {
            caption.gotoAndPlay(2);
    }
}

I works fine if you watch the video from start to finish, the text appears at the right time, does want it's supposed to but if I pause, rewind the video then the text animations animate independently from the timeline.

Is it possible to add the text I need with a different method so the timing of the text animations always matches the timing of the video (without adding the text to the original video file).

I'm using CS3 and AS3. Help would be much appreciated.

Thanks

Dan
0
Dan_Bailey
Asked:
Dan_Bailey
1 Solution
 
IceColdasCommented:
in order to get your task done, either you add cue points for each text position and when triggered play the text at the specified poisition,
or you sync your text with the playing time of the flv, and you add a timer with 200 ms (or less if necessary) trigger time and in that timer you check the playing time of the flv and according to that you set the related text.
For the second approach, you could use this code to start to play the texts. The code can be adjusted to display the texts even more precise, but ... that will imply some more coding.
import fl.video.*;
var flvPlayBack = new FLVPlayback();
flvPlayBack.source = "intro.flv";
this.addChild(flvPlayBack);
var myTexts:MovieClip = new MovieClip();
var currentTextPosition = -1;

var textTime:Array = new Array (3,  5, 14, 23); //  .... here goes your times .... 
var textFrame:Array = new Array (1,  70, 150, 300); //  .... here goes the starting frames for your texts .... 
var timer1:Timer = new Timer(200);
timer1.addEventListener(TimerEvent.TIMER, onTimer);
timer1.start();
function onTimer(ev:TimerEvent)
{
	var textPosition = getTextPosition(flvPlayBack.playheadTime);
	if (textPosition != currentTextPosition && textPosition != -1)
	{
		currentTextPosition = textPosition;
		ShowText(textPosition);
	}
}

function getTextPosition(playTime:Number)
{
	var textPosition:Number = -1;
	for (var i = 0; i < textTime.length - 1; i++)
	{
		if (playTime >= textTime[i] && playTime < textTime[i+1])
		{
			textPosition = i; break;
		}
	}
	return textPosition;
}
function ShowText(textPosition:Number)
{
	trace("showing text at frame:"+textFrame[textPosition]);
	myTexts.gotoAndPlay(textFrame[textPosition]);
}

Open in new window

0
 
CyanBlueCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now