void VideoStartup(IVideoInfo iVideo) {
			playerEngine = new HostedPlayer();
			
			var account = AccountManager.Instance.CurrentAccount;
			UserNameToken usToken = null;
			if (!account.IsAnonymous) {
				usToken = new UserNameToken(account.Name, account.Password);
			}
			playerEngine.SetMetadataReciever(new MetadataFramer((stream) => {
				using (Disposable.Create(() => stream.Dispose())) {
					var xml = new XmlDocument();
					try {
						xml.Load(stream);
						if (xml.DocumentElement != null && xml.DocumentElement.HasChildNodes) {
							
							//TODO: possible incorrect behaviour when multiple instances of odm are running
							if (AppDefaults.visualSettings.EventsCollect_IsEnabled) {
								try {
									using (var sw = AppDefaults.MetadataFileInfo.AppendText()) {
										using (var xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true, CloseOutput = false })) {
											xml.DocumentElement.WriteTo(xw);
										}
										sw.WriteLine();
										sw.WriteLine("<!--------------------------------------------------------------------------------!>");
									}
								} catch {
									//swallow error
								}
							}

							MetadataReceived(xml);
						}
					} catch (Exception err) {

						//TODO: possible incorrect behaviour when multiple instances of odm are running
						if (AppDefaults.visualSettings.EventsCollect_IsEnabled) {
							try {
								using (var sw = AppDefaults.MetadataFileInfo.AppendText()) {
									sw.WriteLine("<!---------------------------------------------------------------------------------");
									sw.WriteLine("ERROR: {0}", err.Message);
									sw.WriteLine("---------------------------------------------------------------------------------!>");
								}
							} catch {
								//swallow error
								dbg.Error(err);
							}
						}

						dbg.Error(err);
					}
				}
			}));
			var vs = AppDefaults.visualSettings;
			MediaStreamInfo.Transport medtranp = MediaStreamInfo.Transport.Tcp;
			switch(vs.Transport_Type){
				case TransportProtocol.http:
					medtranp = MediaStreamInfo.Transport.Http;
					break;
				case TransportProtocol.rtsp:
					medtranp = MediaStreamInfo.Transport.Tcp;
					break;
				case TransportProtocol.tcp:
					medtranp = MediaStreamInfo.Transport.Tcp;
					break;
				case TransportProtocol.udp:
					medtranp = MediaStreamInfo.Transport.Udp;
					break;
			}
			
			MediaStreamInfo mstreamInfo = new MediaStreamInfo(iVideo.MediaUri, medtranp, usToken);
			playerEngine.Play(mstreamInfo, this);

			disposables.Add(playerEngine);
		}
		public IDisposable Play(MediaStreamInfo mediaStreamInfo, IPlaybackController playbackController) {
			//fix url
			var url = new Uri(mediaStreamInfo.url);
			if (url == null || !url.IsAbsoluteUri) {
				throw new Exception("Invalid playback url");
			}
			if (mediaStreamInfo.transport != MediaStreamInfo.Transport.Http) {
				if (String.Compare(url.Scheme, "rtsp", true) != 0) {
					throw new Exception("Invalid playback url");
				}
			} else if (String.Compare(url.Scheme, "rtsp", true) != 0) {
				int defPort;
				if (String.Compare(url.Scheme, Uri.UriSchemeHttp, true) == 0) {
					defPort = 80;
				} else if (String.Compare(url.Scheme, Uri.UriSchemeHttps, true) == 0) {
					defPort = 443;
				} else {
					throw new Exception("Invalid playback url");
				}
				var ub = new UriBuilder(url);
				ub.Scheme = "rtsp";
				if (ub.Port == -1) {
					ub.Port = defPort;
				}
				url = ub.Uri;
				mediaStreamInfo = new MediaStreamInfo(url.ToString(), mediaStreamInfo.transport, mediaStreamInfo.userNameToken);
			}

			var disposable = new SingleAssignmentDisposable();
			playerTask.mediaStreamInfo = mediaStreamInfo;
			playerTask.playbackController = playbackController;
			if (playerHost != null) {
				playerHost.Dispose();
				RemotingServices.Disconnect(playerHost);
				playerHost = null;
			}

			playerHost = new PlayerHost(playerTask);
			RemotingServices.Marshal(playerHost);
			var ipcChannel = AppHosting.SetupChannel();
			var hostControllerUri = RemotingServices.GetObjectUri(playerHost);
			var hostControllerUrl = ipcChannel.GetUrlsForUri(hostControllerUri).First();

			//start player host process
			var hostProcessArgs = new CommandLineArgs();
			var t = Uri.EscapeDataString(hostControllerUrl);
			hostProcessArgs.Add("controller-url", new List<string> { hostControllerUrl });

			var pi = new ProcessStartInfo() {
				FileName = Assembly.GetExecutingAssembly().Location,
				UseShellExecute = false,
				Arguments = String.Join(" ", hostProcessArgs.Format()),
			};
			pi.EnvironmentVariables["PATH"] = String.Join("; ", Bootstrapper.specialFolders.dlls.Select(sfd => sfd.directory.FullName).Append(pi.EnvironmentVariables["PATH"]));

			StartHostProcess(pi);
			return Disposable.Create(() => {
				Dispose();
			});
		}
        public IDisposable Play(MediaStreamInfo mediaStreamInfo, IPlaybackController playbackController)
        {
            //fix url
            var url = new Uri(mediaStreamInfo.url);

            if (url == null || !url.IsAbsoluteUri)
            {
                throw new Exception("Invalid playback url");
            }
            if (mediaStreamInfo.transport != MediaStreamInfo.Transport.Http)
            {
                if (String.Compare(url.Scheme, "rtsp", true) != 0)
                {
                    throw new Exception("Invalid playback url");
                }
            }
            else if (String.Compare(url.Scheme, "rtsp", true) != 0)
            {
                int defPort;
                if (String.Compare(url.Scheme, Uri.UriSchemeHttp, true) == 0)
                {
                    defPort = 80;
                }
                else if (String.Compare(url.Scheme, Uri.UriSchemeHttps, true) == 0)
                {
                    defPort = 443;
                }
                else
                {
                    throw new Exception("Invalid playback url");
                }
                var ub = new UriBuilder(url);
                ub.Scheme = "rtsp";
                if (ub.Port == -1)
                {
                    ub.Port = defPort;
                }
                url             = ub.Uri;
                mediaStreamInfo = new MediaStreamInfo(url.ToString(), mediaStreamInfo.transport, mediaStreamInfo.userNameToken);
            }

            var disposable = new SingleAssignmentDisposable();

            playerTask.mediaStreamInfo    = mediaStreamInfo;
            playerTask.playbackController = playbackController;
            if (playerHost != null)
            {
                playerHost.Dispose();
                RemotingServices.Disconnect(playerHost);
                playerHost = null;
            }

            playerHost = new PlayerHost(playerTask);
            RemotingServices.Marshal(playerHost);
            var ipcChannel        = AppHosting.SetupChannel();
            var hostControllerUri = RemotingServices.GetObjectUri(playerHost);
            var hostControllerUrl = ipcChannel.GetUrlsForUri(hostControllerUri).First();

            //start player host process
            var hostProcessArgs = new CommandLineArgs();
            var t = Uri.EscapeDataString(hostControllerUrl);

            hostProcessArgs.Add("controller-url", new List <string> {
                hostControllerUrl
            });

            var pi = new ProcessStartInfo()
            {
                FileName        = Assembly.GetExecutingAssembly().Location,
                UseShellExecute = false,
                Arguments       = String.Join(" ", hostProcessArgs.Format()),
            };

            pi.EnvironmentVariables["PATH"] = String.Join("; ", Bootstrapper.specialFolders.dlls.Select(sfd => sfd.directory.FullName).Append(pi.EnvironmentVariables["PATH"]));

            StartHostProcess(pi);
            return(Disposable.Create(() => {
                Dispose();
            }));
        }
		void VideoStartup(Model model) {
			player = new HostedPlayer();
			var res = model.encoderResolution;
			videoBuff = new VideoBuffer(res.width, res.height);
			player.SetVideoBuffer(videoBuff);

			var account = AccountManager.Instance.CurrentAccount;
			UserNameToken utoken = null;
			if (!account.IsAnonymous) {
				utoken = new UserNameToken(account.Name, account.Password);
			}

			if (model.metadataReceiver != null) {
				player.SetMetadataReciever(model.metadataReceiver);
			}

			MediaStreamInfo.Transport transp;
			switch (model.streamSetup.transport.protocol) {
				case TransportProtocol.http:
					transp = MediaStreamInfo.Transport.Http;
					break;
				case TransportProtocol.rtsp:
					transp = MediaStreamInfo.Transport.Tcp;
					break;
				default:
					transp = MediaStreamInfo.Transport.Udp;
					break;
			}
			MediaStreamInfo mstrInfo = new MediaStreamInfo(model.mediaUri.uri, transp, utoken);
			disposables.Add(player.Play(mstrInfo, this));
			InitPlayback(videoBuff);
		}