Solved

cue points in flvplayback: sycronising video and text

Posted on 2010-11-18
3
937 Views
Last Modified: 2013-11-11
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
Comment
Question by:Dan_Bailey
3 Comments
 
LVL 3

Accepted Solution

by:
IceColdas earned 500 total points
ID: 34282180
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
 
LVL 37

Expert Comment

by:CyanBlue
ID: 34470594
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now