Switching not working in Playlist
So recently I have found issues with switching when playing playlists in a player we are developing. So to trouble shoot I built a simple application with buttons to manually switch. The first video in the stream switches just fine. When the player gets to to the second video in the the stream, switch does does not work either with or with out oldStreamName defined in the NetStreamPlayOptions. What happens is the the stream ends prematurely, a few seconds to a few minutes after the the button to switch is clicked. If I just let it pIay with out switching it plays out the whole stream as intended. I can't find any reason for this not to work, so I am wondering if there is an issue with the server. Any idea if this could be a server issue or am I missing something here?
Thanks,
Adam
Example is here.
Press button 1 to switch using OldStreamName, button 2 to switch not using OldStreamName, and button 3 to seek to the beggining of the second video in the playlist. There are messages being traced to the the stage so you can see whats happenning.
my AS:
package
{
import Button;
import Playtime; //for netstreamtime to display
import Tracer; //for tracing to sprite on stage
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.NetStreamInfo;
import flash.net.NetStreamPlayOptions;
import flash.net.NetStreamPlayTransitions;
[SWF(width='1280', height='720', backgroundColor='#000000', frameRate='30')]
public class switchTester extends MovieClip
{
private var nc:NetConnection = new NetConnection();
public var stream:NetStream;
private var video:Video;
public var tracer:Tracer = new Tracer();
public var vid:Array = [];
public var currentVid:Object = new Object;
public var nextVid:Object = new Object;
private var pt:Playtime = new Playtime();
public function switchTester()
{
init();
}
private function init():void
{
this.addChild(tracer);
nc.connect("rtmp://yj72wmv1w.rtmphost.com/test");
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncError);
}private function netStatusHandler(e:NetStatusEvent):void
{
tracer.add("NetStatusEvent: " + e.info.code);
if(e.info.code == "NetConnection.Connect.Success")
{
stream = new NetStream(nc);
stream.bufferTime = 10;
stream.backBufferTime = 20;
stream.inBufferSeek = true;
var customClient:Object = new Object() ;
customClient['onPlayStatus'] = onPlayStatus;
stream.client = customClient;
video = new Video(1280,720);
video.attachNetStream(stream);
video.smoothing = true;
this.addChildAt(video,0);
var btnHolder:Sprite = new Sprite();
for (var i:int = 0; 3 > i; i++)
{
var btn:Button = new Button((i+1).toString());
btn.x = btn.width * 1.5 * i;
btn.addEventListener(MouseEvent.MOUSE_UP, onUp);
btnHolder.addChild(btn);
}
btnHolder.x = this.width - btnHolder.width - 10;
btnHolder.y = this.height - btnHolder.height - 10;
this.addChild(btnHolder);
addPlaylist();
}
}private function addPlaylist():void
{for (var i:int = 0; 2 > i; i++)
{
var l:Object = new Object();
var m:Object = new Object();
var h:Object = new Object();
l.quality = "low";
m.quality = "med";
h.quality = "high";
var seg:Array = [l, m, h];
vid.push(seg);
}
vid[0][0].path = "mp4:res_11-15lb_baby_01_500kbps.mp4";
vid[0][1].path = "mp4:res_11-15lb_baby_01_1000kbps.mp4";
vid[0][2].path = "mp4:res_11-15lb_baby_01_1800kbps.mp4";
vid[1][0].path = "mp4:yog_e_8-12_baby_02_VO_v4_500kbps.mp4";
vid[1][1].path = "mp4:yog_e_8-12_baby_02_VO_v4_800kbps.mp4";
vid[1][2].path = "mp4:yog_e_8-12_baby_02_VO_v4_1500kbps.mp4";
stream.play(vid[0][0].path, 0, -1, false);
stream.play(vid[1][0].path, 0, -1, false);
currentVid = vid[0][0];
tracer.add("first video is " + currentVid.path);
tracer.add("second video is " + vid[1][0].path);
pt.x = 1200;
addChild(pt);
}
private function onPlayStatus(info:Object):void
{
tracer.add("onPlayStatus: " + info.code);
if(info.code == "NetStream.Play.TransitionComplete") currentVid = nextVid;
}
private function asyncError(e:AsyncErrorEvent):void
{
tracer.add("asyncError: " + e.error);
}
private function onUp(e:MouseEvent):void
{
switch (e.target.id)
{
case "1":
switchWithOldStream();
break;
case "2":
switchNoOldStream();
break;
case "3":
stream.seek(592.828);
currentVid = vid[1][0];
break;
}
}
private function switchNoOldStream():void
{
var nsi:String = String(stream.info);
var arr:Array = nsi.split(" ");
arr = arr[23].split("resourceName=")
tracer.add("resourceName= " + arr[1]);
setNextVid();
var param:NetStreamPlayOptions = new NetStreamPlayOptions();
param.streamName = nextVid.path;
param.transition = NetStreamPlayTransitions.SWITCH;
stream.play2(param);
tracer.add("switchNoOldStream to: " + nextVid.path);
}
private function switchWithOldStream():void
{
var nsi:String = String(stream.info);
var arr:Array = nsi.split(" ");
arr = arr[23].split("resourceName=")
tracer.add("resourceName= " + arr[1]);
setNextVid();
var param:NetStreamPlayOptions = new NetStreamPlayOptions();
tracer.add("oldStreamName: " + currentVid.path);
param.oldStreamName = "mp4:" + arr[1];
param.streamName = nextVid.path;
param.transition = NetStreamPlayTransitions.SWITCH;
stream.play2(param);
tracer.add("switchWithOldStream to: " + nextVid.path);
}
private function setNextVid():void
{
for (var i:int = 0; vid.length > i; i++)
{
var m:int = i;
for (var n:int = 0; vid.length > n; n++)
{
var arr:Array = vid
if(currentVid == arr)
{
var p:int;
if(n == arr.length-1) p = 0 else p = n+1;
nextVid = arr;
}
}
}
}}
}
Message was edited by: Adam Ashby
