private void OnChat(ChatData data) { // Try to parse the message as a chat command and ignore it if it is not a known command var tokens = data.Message.Split(new char[] { ' ' }); if (CheckCommand(tokens, CommandAgentMediaUrl, 2)) { string url = tokens[1]; AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId); agent.OverrideMediaSource(url); } else if (CheckCommand(tokens, CommandAgentMediaSizeAndUrl, 4)) { Int32 width = Int32.Parse(tokens[1]); Int32 height = Int32.Parse(tokens[2]); string url = tokens[3]; AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId); agent.OverrideMediaSource(url, width, height); } else if (CheckCommand(tokens, CommandSceneMediaUrl, 2)) { string url = tokens[1]; ScenePrivate.OverrideMediaSource(url); } else if (CheckCommand(tokens, CommandSceneMediaSizeAndUrl, 4)) { Int32 width = Int32.Parse(tokens[1]); Int32 height = Int32.Parse(tokens[2]); string url = tokens[3]; ScenePrivate.OverrideMediaSource(url, width, height); } }
private void playRandomSong(List <Tuple <string, string, int> > slist) { Random r = new Random(); int rInt = 0; int nextId = curSongId; //Make sure we don't get the same ID while (nextId == curSongId) { rInt = r.Next(0, slist.Count); nextId = rInt; } curSongId = nextId; msgAll( "Random Play\n" + "[" + (rInt + 1) + "/" + slist.Count + "] " + slist[rInt].Item1 + "\nPlaying Next in " + slist[curSongId].Item3 + " Seconds" ); ScenePrivate.OverrideMediaSource(getYtEmbedUrl(slist[curSongId].Item2)); //TODO: destroy this timer before creating a new one stopYt(false); ytTimer = Timer.Create(TimeSpan.FromSeconds(slist[curSongId].Item3), () => { playRandomSong(slist); }); }
void SubscribeToMessages() { // Already subscribed if (unsubscribes != null) { return; } foreach (var kvp in mediaUrls) { unsubscribes += SubscribeToAll(kvp.Key, (ScriptEventData subData) => { if (PrivateMedia) { ISimpleData simpleData = subData.Data?.AsInterface <ISimpleData>(); if (simpleData != null && simpleData.AgentInfo != null) { AgentPrivate agent = ScenePrivate.FindAgent(simpleData.AgentInfo.SessionId); if (agent != null && agent.IsValid) { try { agent.OverrideMediaSource(kvp.Value, MediaWidth, MediaHeight); } catch (ThrottleException) { // Throttled Log.Write(LogLevel.Warning, "OverrideMediaSource request throttle hit. Media not set."); } catch (NullReferenceException) { // User Left, ignore. } } } } else { try { ScenePrivate.OverrideMediaSource(kvp.Value, MediaWidth, MediaHeight); } catch (ThrottleException) { // Throttled Log.Write(LogLevel.Warning, "OverrideMediaSource request throttle hit. Media not set."); } } }); } }
void Update() { List <string> names = new List <string>(); foreach (AgentPrivate agent in ScenePrivate.GetAgents()) { names.Add(agent.AgentInfo.Handle); } JsonSerializer.Serialize(names.ToArray(), (JsonSerializationData <string[]> data) => { if (data.Success) { ScenePrivate.OverrideMediaSource(url + "#" + data.JsonString); } }); }
private void stopYt(bool blank) { if (ytTimer != null) { ytTimer.Unsubscribe(); ytTimer = null; } else { Log.Write(LogLevel.Warning, GetType().Name, $"No ytTimer Active"); } if (blank) { ScenePrivate.OverrideMediaSource("about:blank"); } }
public override void Init() { // Set the public media source for the scene ScenePrivate.OverrideMediaSource(PublicMedia); // Override the media source to the private media source for each user that clicks on this object ObjectPrivate.AddInteractionData addData = (ObjectPrivate.AddInteractionData)WaitFor(ObjectPrivate.AddInteraction, "Show media", true); addData.Interaction.Subscribe((InteractionData data) => { AgentPrivate agent = ScenePrivate.FindAgent(data.AgentId); if (agent != null) { agent.OverrideMediaSource(PrivateMedia); } }); }
private void PlayVideo(string Video) { bool complete = false; while (complete == false) { try { VideoStartTime = DateTime.Now; VideoCurrentTime = 0; ScenePrivate.OverrideMediaSource(Video, ScreenWidth, ScreenHeight); complete = true; } catch (ThrottleException e) { complete = false; Wait(e.Interval - e.Elapsed); // Wait out the rest of the interval before trying again. } Yield(); }//while }
void OnChat(ChatData data) { AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId); if (!IsAccessAllowed(agent)) { return; } string[] chatWords = data.Message.Split(' '); if (chatWords.Length < 1) { return; } string command = chatWords[0]; if (!_commandsUsage.ContainsKey(command)) { return; } if (command == "/help" || chatWords.Length < 2) { string helpMessage = "MediaChatCommand usage:"; foreach (var kvp in _commandsUsage) { helpMessage += "\n" + kvp.Key + " " + kvp.Value; } try { agent.SendChat(helpMessage); } catch { // Agent left } return; } string medialUrl = ""; if (command == "/media" || chatWords[1].StartsWith("http")) { medialUrl = chatWords[1]; } else if (command == "/yt" || command == "/youtube") { string videoId = chatWords[1]; medialUrl = string.Format("https://www.youtube.com/embed/{0}?autoplay=1&loop=1&playlist={0}&controls=0", videoId); if (chatWords.Length > 2) { int startTime = 0; if (int.TryParse(chatWords[2], out startTime)) { medialUrl += "&start=" + startTime; } } } else if (command == "/ytlive") { string livestreamId = chatWords[1]; medialUrl = string.Format("https://www.youtube.com/embed/live_stream?channel={0}&autoplay=1", livestreamId); } else if (command == "/ytpl") { string playlistId = chatWords[1]; medialUrl = string.Format("https://www.youtube.com/embed?%20listType=playlist%20&list={0}&loop=1&autoplay=1&controls=0", playlistId); } else if (command == "/twitch") { string channelName = chatWords[1]; medialUrl = string.Format("http://player.twitch.tv/?channel={0}&quality=source&volume=1", channelName); } else if (command == "/twitchv") { string videoId = chatWords[1]; medialUrl = string.Format("http://player.twitch.tv/?video={0}&quality=source&volume=1", videoId); } else if (command == "/vimeo") { string videoId = chatWords[1]; medialUrl = string.Format("https://player.vimeo.com/video/{0}?autoplay=1&loop=1&autopause=0", videoId); } bool throttled = false; try { ScenePrivate.OverrideMediaSource(medialUrl); agent.SendChat("Media URL successfully updated to " + medialUrl); Log.Write("New media URL: " + medialUrl); } catch (ThrottleException) { throttled = true; Log.Write("Throttled: Unable to update media URL."); } catch { // Agent left } if (throttled) { try { agent.SendChat("Media URL update was throttled. Try again."); } catch { // Agent left } } }
private void ParseCommands(string DataCmdIn) { Errormsg = "No Errors"; Log.Write("DataCmdIn: " + DataCmdIn); if (DataCmdIn.Contains("/")) { strErrors = false; if (DataCmdIn.Contains("/forcevideo")) { //play video IsWatchFormat = false; Log.Write("video: " + video); Log.Write("video length: " + video.Length); video = DataCmdIn.Substring(12, DataCmdIn.Length - 12); PlayVideo(video); } if (DataCmdIn.Contains("/forcecurrentvideo")) { //play video IsWatchFormat = false; //Log.Write("videoIn: " + videoIn); //Log.Write("videoIn length: " + videoIn.Length); //video = DataCmdIn.Substring(12, DataCmdIn.Length - 12); video = videoIn.Trim(); //Log.Write("video length: " + video.Length); PlayVideo(video); } if (DataCmdIn.Contains("/next")) { string VideoToPlay = null; //Log.Write("PlayList Size: " + PlayList.Count()); //Log.Write("playListPosition: " + playListPosition); if (PlayList.Count() == 0) { Log.Write("No Playlist"); } else if (playListPosition > PlayList.Count() - 1) { playListPosition = 1; } else { playListPosition++; } VideoToPlay = PlayList[playListPosition - 1]; //Log.Write("video: " + VideoToPlay); videoIn = VideoToPlay; if (VideoToPlay.Contains("/watch?v=")) { IsWatchFormat = true; VideoToPlay = URLToEmbedFormat(VideoToPlay); } PlayVideo(VideoToPlay); } if (DataCmdIn.Contains("/previous")) { string VideoToPlay = null; Log.Write("PlayList Size: " + PlayList.Count()); Log.Write("playListPosition: " + playListPosition); if (PlayList.Count() == 0) { Log.Write("No Playlist"); } else if (playListPosition < 1) { playListPosition = PlayList.Count() - 1; } else { playListPosition--; } VideoToPlay = PlayList[playListPosition]; Log.Write("video: " + VideoToPlay); videoIn = VideoToPlay; if (VideoToPlay.Contains("/watch?v=")) { IsWatchFormat = true; VideoToPlay = URLToEmbedFormat(VideoToPlay); } PlayVideo(VideoToPlay); } if (DataCmdIn.Contains("/playlist")) { ScenePrivate.Chat.MessageAllUsers("Playlist Not Yet Implemented"); /* * playListPosition = 0; * string VideoToPlay = null; * keepPlaying = true; * do * { * VideoToPlay = PlayList[playListPosition]; * Log.Write("video: " + VideoToPlay); * videoIn = VideoToPlay; * if (VideoToPlay.Contains("/watch?v=")) * { * IsWatchFormat = true; * VideoToPlay = URLToEmbedFormat(VideoToPlay); * } * PlayVideo(VideoToPlay); * Log.Write("playListPosition" + playListPosition); * if (playListPosition >= PlayList.Count()) * { * playListPosition = 0; * } * else * { * playListPosition++; * } * } while (keepPlaying); */ } if (DataCmdIn.Contains("/shuffle")) { ScenePrivate.Chat.MessageAllUsers("Shuffle Not Yet Implemented"); } if ((DataCmdIn.Contains("/video")) || (DataCmdIn.Contains("/stream"))) { //play video IsWatchFormat = false; video = DataCmdIn.Substring(7, DataCmdIn.Length - 7); videoIn = video; Log.Write("video: " + video); if (DataCmdIn.Contains("/watch?v=")) { IsWatchFormat = true; video = URLToEmbedFormat(DataCmdIn); Log.Write("New Video: " + video); } if (DataCmdIn.Contains("Youtu.be")) { IsWatchFormat = true; video = ShortenedURLToEmbedFormat(DataCmdIn); Log.Write("New Video: " + video); } PlayVideo(video); } if (DataCmdIn.Contains("/play")) { //play video string VideoToPlay = null; Log.Write("DataCmdIn: " + DataCmdIn.Trim()); switch (DataCmdIn.Trim()) { case "/play1": if (Play1.Length > 0) { IsWatchFormat = false; VideoToPlay = Play1; playListPosition = 1; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play1"); } break; case "/play2": if (Play2.Length > 0) { IsWatchFormat = false; VideoToPlay = Play2; playListPosition = 2; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play2"); } break; case "/play3": if (Play3.Length > 0) { IsWatchFormat = false; VideoToPlay = Play3; playListPosition = 3; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play3"); } break; case "/play4": if (Play4.Length > 0) { IsWatchFormat = false; VideoToPlay = Play4; playListPosition = 4; } else { Log.Write("No Play4"); ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play4"); } break; case "/play5": if (Play5.Length > 0) { IsWatchFormat = false; VideoToPlay = Play5; playListPosition = 5; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play5"); } break; case "/play6": if (Play6.Length > 0) { IsWatchFormat = false; VideoToPlay = Play6; playListPosition = 6; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play6"); } break; case "/play7": if (Play7.Length > 0) { IsWatchFormat = false; VideoToPlay = Play7; playListPosition = 7; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play7"); } break; case "/play8": if (Play8.Length > 0) { IsWatchFormat = false; VideoToPlay = Play8; playListPosition = 8; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play8"); } break; case "/play9": if (Play9.Length > 0) { IsWatchFormat = false; VideoToPlay = Play9; playListPosition = 9; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play9"); } break; case "/play10": if (Play10.Length > 0) { IsWatchFormat = false; VideoToPlay = Play10; playListPosition = 10; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play10"); } break; case "/play11": if (Play11.Length > 0) { IsWatchFormat = false; VideoToPlay = Play11; playListPosition = 11; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play11"); } break; case "/play12": if (Play12.Length > 0) { IsWatchFormat = false; VideoToPlay = Play12; playListPosition = 12; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play12"); } break; case "/play13": if (Play13.Length > 0) { IsWatchFormat = false; VideoToPlay = Play13; playListPosition = 13; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play13"); } break; case "/play14": if (Play14.Length > 0) { IsWatchFormat = false; VideoToPlay = Play14; playListPosition = 14; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play14"); } break; case "/play15": if (Play15.Length > 0) { IsWatchFormat = false; VideoToPlay = Play15; playListPosition = 15; } else { ScenePrivate.Chat.MessageAllUsers("No Video in Slot Play15"); } break; default: Errormsg = "Must be Play1 thru Play15"; break; } Log.Write("PlayListPosition: " + playListPosition); Log.Write("video: " + VideoToPlay); videoIn = VideoToPlay; if (VideoToPlay.Contains("/watch?v=")) { IsWatchFormat = true; VideoToPlay = URLToEmbedFormat(VideoToPlay); } PlayVideo(VideoToPlay); } if (DataCmdIn.Contains("/pause") && IsWatchFormat) { intVideoCurrentTime = (int)(DateTime.Now - VideoStartTime).TotalSeconds; video = "https://www.youtube.com/embed/" + EmbedVideoID + "?rel=0&end=1&controls=0&showinfo=0&autoplay=1&allowfullscreen"; Log.Write("Video on pause: " + video); ScenePrivate.OverrideMediaSource(video, ScreenWidth, ScreenHeight); } if (DataCmdIn.Contains("/resume") && IsWatchFormat) { intVideoCurrentTime = (int)(DateTime.Now - VideoStartTime).TotalSeconds; video = "https://www.youtube.com/embed/" + EmbedVideoID + "?rel=0&start=" + intVideoCurrentTime.ToString() + "&controls=0&showinfo=0&autoplay=1&allowfullscreen"; Log.Write("Video on resume: " + video); ScenePrivate.OverrideMediaSource(video, ScreenWidth, ScreenHeight); } if (DataCmdIn.Contains("/stop") && IsWatchFormat) { intVideoCurrentTime = 0; VideoStartTime = DateTime.Now; EmbedVideoID = "4wTPTh6-sSo"; video = "https://www.youtube.com/embed/" + EmbedVideoID + " ?rel=0&controls=0&showinfo=0&autoplay=1&allowfullscreen"; Log.Write("Video on pause: " + video); ScenePrivate.OverrideMediaSource(video, ScreenWidth, ScreenHeight); keepPlaying = false; } if (DataCmdIn.Contains("/volumeUp")) { Log.Write("In volumeUp"); float curLoudness = currentPlayHandle.GetLoudness(); curLoudness = curLoudness + 5; currentPlayHandle.SetLoudness(curLoudness); } if (DataCmdIn.Contains("/volumeDown")) { Log.Write("In volumeDown"); float curLoudness = currentPlayHandle.GetLoudness(); curLoudness = curLoudness - 5; currentPlayHandle.SetLoudness(curLoudness); } /* * * if (DataCmdIn.Contains("/commands")) * { * DisplayHelp(agent); * * } */ } }
public override void Init() { Script.UnhandledException += UnhandledException; //Init Songlist var songlist = new List <Tuple <string, string, int> > { Tuple.Create("Fmaa", "vtfKVoUYzyE", 56), Tuple.Create("Cirrus", "WF34N4gJAKE", 202), Tuple.Create("Boy & Bear", "sy4IhE-KAEg", 205), Tuple.Create("We Are Number One", "DUzBtXi-9Bs", 163), Tuple.Create("Spocktopus", "qc57-IcwnB0", 196), Tuple.Create("Warriors", "Ve_p5lfYIIs", 260), Tuple.Create("Miami Nights 1984", "rDBbaGCCIhk", 234), Tuple.Create("The Awakening", "i_Pn4myR8Cw", 334), Tuple.Create("Never Dance Again (Battle Tapes Remix)", "cmW4d7CrqBw", 251), Tuple.Create("Out For A Rip", "F-glHAzXi_M", 210) }; var playlists = new List <Tuple <string, string, int> > { Tuple.Create("Pogo", "PLupdJjxWWYR55JN3UlaQdS2LPe5-fjlx7", 28), Tuple.Create("Jaboody Dubs", "PLSZtrpAn6e8eP_U7Fbf-jA2ob-76IqY2u", 24) }; ScenePrivate.Chat.Subscribe(0, (ChatData data) => { if (isSmoCmd(data)) { //remove cmdChar string cmdstr = data.Message.Substring(1, data.Message.Length - 1); //split on sep max 3 parts string[] parts = cmdstr.Split(new string[] { " " }, 3, StringSplitOptions.RemoveEmptyEntries); //find out operation if (parts.Length > 0) { string oper = parts[0].ToLower(); switch (oper) { case "commands": msgId(data.SourceId, "\nCommand List: " + "\n " + cmdChar + "yt Plays youtube urls" + "\n " + cmdChar + "ytpl Plays youtube playlist" + "\n " + cmdChar + "reset Reset experience" + "\n " + cmdChar + "about About experience" + "\n " + cmdChar + "commands This command" + "\n " ); break; case "about": SceneInfo info = ScenePrivate.SceneInfo; msgId(data.SourceId, "About: " + info.ExperienceName + "\n- AvatarId: " + info.AvatarId ); break; case "yt": //Make sure there is parameter if (parts.Length > 1) { //string ytUrl = parts[2]; string ytUrl = getYtEmbedUrl(parts[1]); msgId(data.SourceId, "yturl: " + ytUrl); stopYt(false); ScenePrivate.OverrideMediaSource(ytUrl); } else { playRandomSong(songlist); } break; case "ytpl": stopYt(false); if (parts.Length > 1) { string ytPlUrl = getYtPlEmbedUrl(parts[1]); msgId(data.SourceId, "ytplurl: " + ytPlUrl); ScenePrivate.OverrideMediaSource(ytPlUrl); } else { Random r = new Random(); int rInt = r.Next(0, playlists.Count); msgAll( "[" + (rInt + 1) + "/" + playlists.Count + "]" + playlists[rInt].Item1 ); curPlayId = rInt; ScenePrivate.OverrideMediaSource(getYtPlEmbedUrl(playlists[rInt].Item2)); } break; case "live": stopYt(false); ScenePrivate.OverrideMediaSource("http://wantsmo.com:8000/live.html"); msgAll("Starting Stream Please Stand By"); break; case "url": if (parts.Length > 1) { ScenePrivate.OverrideMediaSource(parts[1]); } break; case "stop": stopYt(true); break; case "reset": msgAll("Reset in 5 seconds"); Wait(TimeSpan.FromSeconds(5)); ScenePrivate.ResetScene(); break; default: //msgId(data.SourceId, "Invalid Command"); break; } } } }); //Play some random youtubes playRandomSong(songlist); }