To preface this my knowledge of AS3 is quite novice. As the thread titled reads, I'm trying to get an FLV to play through it's entireity and then loop back towards a specific frame and keep replaying from the point endlessly. After a lot of digging I found a video tutorial using AS3 that worked! Here's my situation now though, I cannot find the right code to insert to make the video loop back to the frame that I want. The FLV just stops and doesnt rewind at the end of the video. Here is my code so far:
var video:Video = new Video(1980, 1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var meta:Object = new Object ();
meta.onMetaData = function (meta: Object)
{
trace(meta.duration);
}
ns.client = meta;
video.attachNetStream(ns);
ns.play("All.flv");
Ultimately, the video needs to play all the way through only on the first load and then loop back to frame 319 and play toward the end and loop back again to frame 319 infinitely. I think I'm almost there, I just need some assistance with getting my code working appropriately. I done this before using "gotoAndPlay()" but the loop isnt seamless thus it yields a one second pause before looping back. I'm hoping using a Netstream function that this will be resolved. I would appreciate any help!
should I implement this code after mine? Or does it need to be inserted in a specific line(s)
Thanks!
Update: I inserted the code as follows:
var video:Video = new Video(1980, 1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var meta:Object = new Object ();
meta.onMetaData = function (meta: Object)
{
trace(meta.duration);
}
ns.client = meta;
video.attachNetStream(ns);
ns.play("All.flv");
meta.onPlayStatus = function(obj:Object):void{
if(obj.code=="NetStream.Play.Complete"){
ns.seek(318);
}
}
Unfortunately the video still stops and pauses in the last frame of the video. I didn't receive any compile errors though, definitely a step in the right direction.
-m
Hi again! The video's total duration is 16.282 seconds. However when it ends on the first run it needs to loop back to frame 318 (or whatever the quivalent that is in seconds). After it loops back to frame 318 it should play to the end again ( at 16.282 seconds) and then loop back to 318 ad infinitum.
I tried the ns.seek script using seconds instead of the frame #, the project is still freezing on the last frame of the video. I took a screenshot to give a visual of my timeline / actionscript window. Maybe it will be of some assistance. If need be I can post a .swf.
Here is the code once again:
var video:Video = new Video(1980, 1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var meta:Object = new Object ();
meta.onMetaData = function (meta: Object)
{
trace(meta.duration);
}
ns.client = meta;
video.attachNetStream(ns);
ns.play("All.flv");
meta.onPlayStatus = function(obj:Object):void{
if(obj.code=="NetStream.Play.Complete"){
ns.seek(10.18);
}
}
what's the trace output from:
var video:Video = new Video(1980, 1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var meta:Object = new Object ();
meta.onMetaData = function (meta: Object)
{
trace(meta.duration);
}
ns.client = meta;
video.attachNetStream(ns);
ns.play("All.flv");
meta.onPlayStatus = function(obj:Object):void{
trace(obj.code);
if(obj.code=="NetStream.Play.Complete"){
trace("seek");
ns.seek(10.18);
}
}
there's a problem with your flv.
try: http://www.helpexamples.com/flash/video/water.flv
and change your seek to 3 or 4.
Okay, I downloaded the water.flv, i had no problems playing the video in the FLV video player (so no problems with the FLV itself). I then moved water.flv into my project directory. Upon moving the water video into the project directory I changed the actionscript lines "ns.seek(4);" and the "ns.play(filename);" as you suggested. The same issue happens, the video plays and freezes on the last frame. Here is my code again for reference:
var video:Video = new Video(1980, 1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var meta:Object = new Object ();
meta.onMetaData = function (meta: Object)
{
trace(meta.duration);
}
ns.client = meta;
video.attachNetStream(ns);
ns.play("water.flv");
meta.onPlayStatus = function(obj:Object):void{
trace(obj.code);
if(obj.code=="NetStream.Play.Complete"){
trace("seek");
ns.seek(4);
}
}
I also decided to run a debug on the FLV video in flash, using the debug movie command and I received this bit of output:
Attempting to launch and connect to Player using URL /Users/mitchp*****/Desktop/ART/Art (DO NOT DELETE!)/Digital work/Views/View I/L2.swf
[SWF] Users:mitchpatrick:Desktop:ART:Art (DO NOT DELETE!):Digital work:Views:View I:L2.swf - 1842 bytes after decompression
*** Security Sandbox Violation ***
Connection to All.flv halted - not permitted from file:///Users/mitchp*****/Desktop/ART/Art (DO NOT DELETE!)/Digital work/Views/View I/L2.swf
SecurityError: Error #2148: SWF file file:///Users/mitchp*****/Desktop/ART/Art (DO NOT DELETE!)/Digital work/Views/View I/L2.swf cannot access local resource All.flv. Only local-with-filesystem and trusted local SWF files may access local resources.
at flash.net::NetStream/play()
at L2_fla::MainTimeline/frame1()[L2_fla.MainTimeline::frame1:25]
From reading this, and from what I can understand, it seems like it's having an issue with file system / access permissions. I think this debug log is pointing to the possible culprit, and hopefully a solution can be made!
Thanks for sticking with me. Let me know if I can corroborate any more details.
-m
what's the trace output using the following and does water.flv continually loop?:
var video:Video = new Video(1980, 1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var meta:Object = new Object ();
meta.onMetaData = function (meta: Object)
{
trace(meta.duration);
}
ns.client = meta;
video.attachNetStream(ns);
ns.play("http://www.helpexamples.com/flash/video/water.flv");
meta.onPlayStatus = function(obj:Object):void{
trace(obj.code);
if(obj.code=="NetStream.Play.Complete"){
trace("seek");
ns.seek(2);
}
}
then you can use:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function netStatusF(e:NetStatusEvent):void {
switch (e.info.code) {
case "NetStream.Play.Stop":
ns.seek(2);
break;
}
};
Okay this did the trick! Just one detail that makes all the differenence. Fortunately there is no 1 second pause in the loop which is perfect, however there is a glitch, and I don't know if this is just the nature of the program or it's exsisting in some form of as3 syntax. I've provided a link for reference:
http://mitchpatrick.com/INT.swf
I determined the exact time it needs to hit for it to be a perfect palindrome loop, I programmed it to loop back to (frame 319) in seconds that is 10.6106, so in theory it should be looping seamlessly. However it's glitching, and I've toyed around with the timecode in the "ns.seek" line, but it seems nearly impossible due to the fact that I can get so damn infinitesimal with those numbers. Here is the code for further reference:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function netStatusF(e:NetStatusEvent):void {
switch (e.info.code) {
case "NetStream.Play.Stop":
ns.seek(10.6106);
break;
}
};
Okay let me try and get this checked through you before I attempt to implement what you've recommend for a seamless loot at the aformentioned time in the previous post:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(
Event.ENTER_FRAME,); <-----not too sure about the rest of the syntax herens.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function netStatusF(e:NetStatusEvent):void {
switch (e.info.code) {
case "NetStream.Play.Stop":
ns.seek(10.6106);
break;
}
};
Hmmm, curious about where the"loop" and ns.time syntax should be placed.
use:
mitwyatt85 wrote:
Okay let me try and get this checked through you before I attempt to implement what you've recommend for a seamless loot at the aformentioned time in the previous post:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
this.addEventListener(
Event.ENTER_FRAME,f); <-----not too sure about the rest of the syntax herens.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function f(e:Event):void {
if(ns.time>16){ // tweak both these numbers to get close to what you want.
ns.seek(10.6);
};
Hi Kgald, I made the adjustments to the code, but for some reason it's reverting back to the problem I had to begin with as the video is freezing on the last frame. Here is the code for reference:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(Event.ENTER_FRAME,f);
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function f(e:Event):void {
if(ns.time>16.2){
ns.seek(10.6);
};
}
No syntax errors were given, I also tried tweaking the ns.time and ns.seek numbers but to no avail, the video still freezes upon entering the last frame.
Hey Adn,
The previous method before using this netstream approach was importing the FLV and extending all the frames of it in the time-line and using the "gotoAndPlay" function, this didn't work because the loop wasnt seamless, there was an annoying 1 second pause before it looped back to the frame I wanted. (see my first post)
The as3 code I'm using now is just calling up the .flv video from the folder the .FLA project file is located in, it's pure code at this point. See post 7 for a screenshot of my project area.
Kgald - The frames are not extended, please refer to post 7 with my screenshot. In my project there is only one layer with a frame containing the action-script 3 we've been working with the entire time. Concerning the "16.2". I changed it to 16 but to no avail, the video still freezes on the last frame, here is the code:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(Event.ENTER_FRAME,f);
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function f(e:Event):void {
if(ns.time>16){
ns.seek(10.6);
};
}
what's the trace output (don't include the repeat values at the end):
980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(Event.ENTER_FRAME,f);
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function f(e:Event):void {
if(ns.time>14){
trace(ns.time);
}
if(ns.time>16){
ns.seek(10.6);
};
}
I was given this under the output tab 16.282. The FLV still freezes at the end, here's my current code for reference:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(Event.ENTER_FRAME,f);
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function f(e:Event):void {
if(ns.time>14){
trace(ns.time);
}
if(ns.time>16){
ns.seek(10.6);
};
}
Upon testing the movie the screen goes completely white and I get a syntax error on that line -
"the.addEventListener(Event.ENTER_FRAME,f);"
"Scene 1, Layer 'actions', Frame 1, Line 6 1120: Access of undefined property the."
Here's my code:
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
the.addEventListener(Event.ENTER_FRAME,f);
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function f(e:Event):void {
if(ns.time>16){
ns.seek(10);
};
}
Since this thread seems to be dragging on with no resolution, I'll throw in my two cents worth.
It's very easy to loop a NetStream video... at least in AS2.. perhaps you can use/adapt this working code:
/* Video player created by CI Digital Media for educational purposes */
stop();
var nc:NetConnection = new NetConnection();
nc.connect(null);var ns:NetStream = new NetStream(nc);
video_screen.attachVideo(ns);
/* Name of your video, with correct path, goes here */
ns.play("loop_vid.flv");ns.onStatus = function(info) {
if(info.code == "NetStream.Play.Stop") {
trace("Video complete")
ns.seek(20);
}
}
See in action here:
http://www.cidigitalmedia.com/tutorials/loop_vid/loop_vid.html
Of course there are multiple other things you could also do at the end of the video, for example:
ns.onStatus = function(info) {
if(info.code == "NetStream.Play.Stop") {
trace("Video complete")
ns.seek(60);
// ns.play();
ns.pause();
// gotoAndStop("end");
getURL("http://www.cidigitalmedia.com/video.html", "_blank");
}
}
You could seek and then pause the video at a certain place.
You could jump to another part of the main time and display/play something else after video is over,
or you could open another Web page upon completion of the video.
All very useful stuff... NetStream is a very versatile and powerful way to work with video.
Again, examples above are AS2.
Best wishes,
Adninjastrator
Okay, some good news, I received the proper trace output :
16.282
14.014
14.047
14.08
14.114
14.147
14.181
14.247
14.247
14.314
14.314
14.348
14.381
14.414
14.448
14.514
14.514
14.547
14.58
14.647
14.647
14.681
14.747
14.747
14.814
14.814
14.848
14.881
14.914
14.948
14.981
15.015
15.048
15.081
15.115
15.148
15.182
15.248
15.248
15.282
15.315
15.349
15.382
15.415
15.449
15.515
15.515
15.548
15.581
15.615
15.648
15.715
15.715
15.748
15.782
15.815
15.849
15.915
15.915
15.949
15.982
16.016
16.049
16.082
16.116
16.149
16.183
16.249
16.249
14.047
14.08
14.08
14.147
14.147
Here is my current set of codes, it's looping once again, but still glitching upon hitting the last frame.
var video:Video=new Video(1980,1020);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
this.addEventListener(Event.ENTER_FRAME,f);
ns.client = this;
video.attachNetStream(ns);
ns.play("All.flv");
function onMetaData(obj:Object):void{
trace(obj.duration);
}
function f(e:Event):void {
if(ns.time>14){
trace(ns.time);
}
if(ns.time>16.24){
ns.seek(10.61);
};
}
I tried tweaking the >16.24) and the (10.61), but no difference was made in fixing the glitch to get a seamless loop.
North America
Europe, Middle East and Africa
Asia Pacific