# Seamless transition between two videos

**URL:** <https://forum.kirupa.com/t/seamless-transition-between-two-videos/309749>\
**Category:** flash\
**Created:** [May 24, 2010, 3:30am UTC](https://forum.kirupa.com/t/seamless-transition-between-two-videos/309749 "2010-05-24T03:30:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [May 24, 2010, 3:30am UTC](https://forum.kirupa.com/t/seamless-transition-between-two-videos/309749/1 "2010-05-24T03:30:15Z")

</div>

[SIZE=“4”] **Question** [/SIZE]

How can I have seamless transitions between videos in a playlist? My video is chunked up into 10 second segments (for reasons that are out of the scope of this question). Currently, the transition is not smooth. Sometimes there is a short flicker of blackness and other times there is a gap in the audio. It’s unpredictable which one will occur.

The problem is not with the video encoding. I have tried both FFMPEG and Flash Media Encoder to chunk up my video. When repackaged back into one whole video, it plays fine in VLC Media Player.

[SIZE=“4”] **Live example** [/SIZE]

Here is an example of two chunks played back to back.

[LIST]  
[_]Demo: [http://levichi.com/flashPlaylist/Seamless.html](http://levichi.com/flashPlaylist/Seamless.html)  
[_]FLA: [http://levichi.com/flashPlaylist/Seamless.fla](http://levichi.com/flashPlaylist/Seamless.fla)  
[\*]AS: [http://levichi.com/flashPlaylist/Seamless.as](http://levichi.com/flashPlaylist/Seamless.as)  
[/LIST]

[SIZE=“4”] **Code** [/SIZE]

This is a bare-bones program that illustrates my issue. It only plays two chunks. My actual code is generalized to work with a huge array of video chunks.

```php

import Seamless;
var s:Seamless = new Seamless(stage);

```

```php

package
{
	import flash.net.*;
	import flash.events.*;
	import flash.media.*;
	import flash.display.*;

	public class Seamless
	{    
		private var vid:Video;            
		private var vidStream0:NetStream;
		private var vidStream1:NetStream;
		
		public function Seamless(container:Stage)
		{
			var vidConnection0:NetConnection = new NetConnection();
			var vidConnection1:NetConnection = new NetConnection();

			vidConnection0.connect(null);
			vidConnection1.connect(null);

			this.vidStream0 = new NetStream(vidConnection0);
			this.vidStream1 = new NetStream(vidConnection1);

			var monitor:Object = new Object();
			monitor.onMetaData = this.onMetaData;
			monitor.onCuePoint = this.onCuePoint;

			vidStream0.client = monitor;
			vidStream1.client = monitor;
		
			this.vidStream0.addEventListener(NetStatusEvent.NET_STATUS, this.transitionToVid1);
			this.vidStream1.addEventListener(NetStatusEvent.NET_STATUS, this.pauseVid1);
			
			this.vid = new Video(960, 540);
			this.vid.attachNetStream(this.vidStream0);
			container.addChild(this.vid);
			
			this.vidStream0.play("2.flv");
			this.vidStream1.play("3.flv");
		}
		
		/**
		 * When video 0 reaches it's end, it needs to tell video 1 to start playing.
		 */
		private function transitionToVid1(event:NetStatusEvent):void
		{
			if (event.info.code == "NetStream.Play.Stop") {
				this.vidStream0.removeEventListener(NetStatusEvent.NET_STATUS, this.transitionToVid1);
				this.vid.clear();
				this.vid.attachNetStream(this.vidStream1);
				this.vidStream1.resume();
			}
		}
		
		/**
		 * Pause video 1 after it has been initiated, so it can buffer while video 0
		 * is playing.
		 */
		private function pauseVid1(event:NetStatusEvent):void
		{
			if (event.info.code == "NetStream.Play.Start") {
				this.vidStream0.removeEventListener(NetStatusEvent.NET_STATUS, this.pauseVid1);
				this.vidStream1.pause();
			}
		}
		
		/**
		 * Required to prevent runtime errors when the video spits out meta data at 
		 * certain places times.
		 */
		private function onMetaData(info:Object):void {
			//trace("duration:", info.duration);
		}
		
		/**
		 * Requried to prevent runtime errors when the video hits cuepoints at certain
		 * places.
		 */
		private function onCuePoint(info:Object):void {
			//trace("cuepoint:", info.parameters.text);
		}
	}
}

```
