dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [CS3] Pause flv on frame 1 whilst it buffers?

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    260

    [CS3] Pause flv on frame 1 whilst it buffers?

    Hi there,

    The site I'm developing at the moment has an FLV at the beginning which is used as an intro animation. I'm streaming it in using netStream but I've run into a problem.
    Is it possible to have th flv pause on the first frame of the video and then play once enough has been buffered? At the moment it shows a black screen sometimes.

    I thought that a way to combat this would be to have a screenshot of the first frame that I display until it starts playing and then just remove it once the video gets to frame 2. However, I don't know how to track whether the playhead has gone past the first frame in flvs.

    Can anyone shed any light?

    Cheers
    Matt

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Posts
    260
    Right,
    I think I've solved part of the problem. basically I have a still of the first frame that I set to alpha = 0 once the netStream.time > 0. So in theory once it starts playing the image disappears and you are left with the video.
    This all works fine the first time you see it. However, if you refresh the page, the image shows but it quckly disappears and a black screen replaces it, and then a second later the flv is playing but not from the start.

    my code is:
    PHP Code:
    this.onEnterFrame = function()
    {
        
    //trace(netStream.time);
        
    if (netStream.time 0)
        {
            
    firstFrame._alpha 0;
        }
        else
        {
            
    //trace("buffering");
        
    }
        
        if (
    netStream.time == _global.ml)
        {
            
            
    qfintro();
            
    delete this.onEnterFrame;
            
    fadeThisQuicker(restingFrame100);
            
    netStream.close();
        }
    }

    netStream.onStatus = function(statusInfo)
    {

        if (
    statusInfo.code == "NetStream.Play.Stop"
        {
            
    introDone.text "COmplete - play something";
            
    qfintro();
            
    delete this.onEnterFrame;
            
    fadeThisQuicker(restingFrame100);
        }
        if (
    statusInfo.code == "NetStream.Buffer.Flush")
        {
            
    trace("started");
            
    firstFrame._alpha 0;
        }

    Can anyone shed some light on this because I'm going mad trying to fix it.

    Cheers
    Matt

  3. #3
    Member
    Join Date
    May 2003
    Location
    Florida
    Posts
    90
    here's a class i have written for this (http://www.bsnonline.net/vision) to handle the movie playback.
    it attaches a movie clip that shows buffering and only starts playing after the buffer is full.

    Code:
    class vidz extends MovieClip
    {
    	private var my_video:Video;
    	private var videoHost:MovieClip;
    	private var videoName:String;
    	private var my_nc:NetConnection;
    	private var my_ns:NetStream;
    	public var myDuration:Number;
    	public var myInt;
    	public var desc:String;
    	public var mySound:Sound;
    	
    	public function vidz(_videoName:String, _videoHost:MovieClip, _desc:String)
    	{
    		desc = _desc;
    		videoName = _videoName;
    		videoHost = _videoHost;
    	
    		var ref = this;
    		var tempX = videoHost._width+18;
    		videoHost._x = tempX;
    		videoHost._y = 48;
    		
    		my_video = videoHost.my_video// my_video is a Video object on the Stage
    		my_video._height = 303;
    		my_video._width = 538;
    		videoHost.scrubz._y = 313;
    		
    		my_nc = new NetConnection();
    		my_nc.connect(null);
    		
    		my_ns = new NetStream(my_nc);
    		
    		my_ns.setBufferTime(15); //10s seconds of buffer
    		my_video.attachVideo(my_ns);
    		
    		my_ns.play("sectionThumbs/videos/"+videoName+".flv");
    		
    		getBuffer();
    		
    		myDuration = null;
    		
    		my_ns.onMetaData = function(info:Object)
    		{
    			ref.myDuration = info.duration;
    			
    			ref.videoHost.attachMovie("MOV_SCRUBBAR", "scrubBar", ref.videoHost.getNextHighestDepth(), {_y:313}); // attaches the scrub bar
    			ref.checkLoad();
    		}
    	}
    	
    	
    	public function checkLoad()
    	{
    		var ref= this; //reference to class to be used in the outer scopes
    		
    		function loading()
    		{
    			if(ref.my_ns.bytesLoaded == ref.my_ns.bytesTotal)
    			{
    				ref.videoHost.scrubBar.scrubz3._width = 419;
    				clearInterval(ref.myInt);
    				delete ref.myInt;
    			}
    			else
    			{
    				ref.videoHost.scrubBar.scrubz3._width = Math.round((ref.my_ns.bytesLoaded/ref.my_ns.bytesTotal)*419);
    			}
    		}
    		myInt = setInterval(loading, 250);
    		
    		videoHost.createEmptyMovieClip("vSound", videoHost.getNextHighestDepth());
    		videoHost.vSound.attachAudio(my_ns);
    		mySound = new Sound(videoHost.vSound);
    		
    	}
    	
    	
    	public function pauseMe(_val:Boolean):Void
    	{
    		my_ns.pause(_val);
    	}
    	
    	public function scrub(_to:Number):Void
    	{
    		my_ns.seek(_to);
    	}
    	
    	
    	public function getDuration()
    	{
    		return myDuration;
    	}
    	
    	
    	public function timer()
    	{
    		return Math.round(my_ns.time);
    	}
    	
    	public function updateSound(_pos:Number, _dist:Number)
    	{
    		var perc:Number = Math.round((_pos-5)/_dist*100);
    		mySound.setVolume(perc);
    	}
    		
    	public function getDownload()
    	{
    		var tempName = videoName+"_Large.mov";
    		return tempName;
    	}
    	
    	
    	/*function that displays the buffer state*/
    	private function getBuffer()
    	{
    		var buffer_interval = setInterval(checkBufferTime, 100, my_ns);
    		
    		_root.attachMovie("MOV_BUFFER", "bufferMov", _root.getNextHighestDepth(), {_x: Stage.width/2-45, _y:Stage.height/2});
    		
    		function checkBufferTime(my_ns:NetStream):Void 
    		{
    			var bufferPct = Math.round((my_ns.bufferLength/my_ns.bufferTime)*100);
    			_root.bufferMov.buff.bufferTXT.text = "buffering "+ bufferPct + "%";
    			if(bufferPct >= 100) 
    			{
    				_root.bufferMov.removeMovieClip();
    				clearInterval(buffer_interval);
    			}
    		}
    	}
    									
    
    }
    visit my portfolio and sign my guestbook!!

  4. #4
    Senior Member
    Join Date
    Apr 2001
    Posts
    260
    Hi all,

    Sorry to drag up an old thread but the problem I initially stated is persisting.

    I've got an flv which is an intro to a site. It plays wonderfully first time but then if you refresh the browser it goes black and starts playing a second or into the flv. I need to clear my cache in order to reset it and get it to play nicely.
    This is how I'm calling it:
    PHP Code:
    intro();
    function 
    intro()
    {
        
    netStream.seek(1);
        
        if (
    _global.viewIntro == true)
        {
            
    netStream.setBufferTime(10);
            
    netStream.play("flv/intro.flv");
            
    _global.viewIntro false;
        }
        else
        {
            
    fadeThisQuicker(restingFrame100);
            for (
    i=0i<4i++)
            {
                var 
    ri restingFrame["resting"+i];
                
    ri.enabled true;
            }
            
    firstFrame._alpha 0;
        }

    I cannot for the life of me understand why it's doing this. The clearing my cache thing hints at a solution but I can't find it.

    Can any one please please pleae help me on this?

    matt

    EDIT: By the way, thank you Cesspenar for your response - I didn't use it as it was written in AS2

  5. #5
    Member
    Join Date
    Sep 2010
    Posts
    41
    This sounds great and just what I was looking for. Is it possible for you to write it in AS3 and repost?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center