Copy link to clipboard
Copied
I'm testing out below code from 'Actionscript Classroom in a Book' to have the flv playback component play a series of video's from an xml file. Now every time a new video starts through the ChangeVid function it starts with loading it first of course. So between each video there is a short period where the flv component is transparent. What I would like is to have the next videos play seamlessly one after the other so there isn't any break visible. Is that possible? Someway to preload the next videos from the list? So that I use vidPlayer.source = 'file1' and while that is playing preset/load the next vidPlayer.source = 'file2' so that when file1 has finished playing vidPlayer source has already been set/loaded to file2?
import fl.events.SliderEvent;
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
import fl.video.*;
var vidList_XML:XML;
var vidTitle:String;
var count:int = 0;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("vidlist.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
vidList_XML = new XML(xmlLoader.data);
vidPlayer.addEventListener(VideoEvent.COMPLETE, changeVid);
}
function changeVid(e:VideoEvent):void
{
var nextVid:String = vidList_XML.vid[count].file;
vidPlayer.source = nextVid;
vidTitle = vidList_XML.vid[count].name;
title_txt.text = vidTitle;
vidPlayer.skinBackgroundColor = Math.random() * 0xFFFFFF;
count++;
}
alphaSlide.addEventListener(SliderEvent.CHANGE, alphaChange);
function alphaChange(e:SliderEvent):void
{
vidPlayer.skinBackgroundAlpha = e.target.value;
}
colorChoose.addEventListener(ColorPickerEvent.CHANGE, changeHandler);
function changeHandler(e:ColorPickerEvent):void
{
var cp:ColorPicker = e.currentTarget as ColorPicker;
vidPlayer.skinBackgroundColor = Number("0x" + cp.hexValue);
}
vidPlayer.source = "../video/solution5.f4v";
vidPlayer.addASCuePoint(10, "BuyCD");
vidPlayer.addEventListener(MetadataEvent.CUE_POINT, cuePointNav);
function cuePointNav(e:MetadataEvent):void
{
if (e.info.name == "BuyCD")
{
title_txt.text = "Click to Purchase Music by Nan Jing";
title_txt.addEventListener(MouseEvent.CLICK, buyCD);
}
}
function buyCD(e:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.cdfreedom.com/artists/passionrecords/catalog/nanjing/"));
}
Copy link to clipboard
Copied
it's possible but you'll need to rethink how/when you want your videos to start because you probably don't want to start loading the "next" video while the current one is still downloading. so, you'll want to check if the current has completed it's download and if the user's bandwidth is less than your current videos bitrate, you have a lot to think about.
in any case, to preload a video, start it and then immediately pause it.
Copy link to clipboard
Copied
But when I set the first video with vidPlayer.source='video1' and it is playing (after having been preloaded), then while it's playing I can't user vidPlayer.source='video2' to meanwhile preload that one so that it immediately starts after video 1 has ended. That would quit video1 and start video2, wouldn't it?
Copy link to clipboard
Copied
use a different flvplayback component.
Copy link to clipboard
Copied
Probably would be better (and simpler) to leave it as it is. But then at least keep showing the last frame of the old video before the next video starts if that's possible.
I've now placed a black background beneath the flvplayback component. So video1 starts, then the black rectangle shows while the source of video2 is set and being downloaded, then video2 continues. Otherwise there would be a tiny 'flash' or transparent moment between video1 and video2.
What would be an improvement is:
- video1 is playing
- video1 has finished but the flvplayback component freezes on it's last frame image
- meanwhile the flvplayback source is set to video2
- video2 continues playing
Is there a way for the flvplayback component to make it pause on it's last frame while loading the next video? Or does loading/sourcing it always make the component go blank first?
Copy link to clipboard
Copied
Never mind, already found a way:
import fl.video.*;
vidPlayer.autoRewind = false;
vidPlayer.addEventListener(fl.video.VideoEvent.COMPLETE, changeVid);
vidPlayer.source = "renee.flv";
function changeVid(e:fl.video.VideoEvent):void
{
// Take the snapshot
var myBitmapData:BitmapData = new BitmapData(vidPlayer.width,vidPlayer.height);
var img = myBitmapData.draw(vidPlayer);
var bmp:Bitmap = new Bitmap(myBitmapData);
addChild(bmp);
setChildIndex(bmp,0);
bmp.x = vidPlayer.x;
bmp.y = vidPlayer.y;
vidPlayer.source = "kurt.flv";
}
When the first video ends it makes a snapshot of its final frame and places it in the background. Then video 2 continues on top of that. Now at least there isn't a too noticable 'blink' between videos (be it the background color or transparent). Just a slight pause of each final frame but I can live with that