Ejemplo n.º 1
0
 public static void CheckPlayInfoEventArgs(PlayInfoEventArgs args, QueueItem item)
 {
     Assert.AreSame(item.AudioResource, args.PlayResource.BaseData);
     Assert.AreSame(item.MetaData, args.PlayResource.Meta);
     Assert.AreEqual(item.MetaData.ResourceOwnerUid, args.Invoker);
     Assert.AreSame(args.ResourceData, item.AudioResource);
 }
Ejemplo n.º 2
0
 private new void InvokeAfterResourceStarted(object sender, PlayInfoEventArgs e)
 {
     if (!ReferenceEquals(sender, currentTask.StartSongTask))
     {
         return;
     }
     base.InvokeAfterResourceStarted(sender, e);
 }
Ejemplo n.º 3
0
        private void PlayManager_AfterResourceStarted(object sender, PlayInfoEventArgs e)
        {
            Console.WriteLine("sd");
            var title  = e.ResourceData.ResourceTitle;
            var length = 2.0m.ToString(bot.PlayerConnection.Length.ToString());

            bot.QueryConnection.SendChannelMessage("Now playing " + title + " (" + length + ")");
        }
Ejemplo n.º 4
0
        public void Play()
        {
            Assert.IsNotNull(preparingItem);
            var e = new PlayInfoEventArgs(PreparingItem.MetaData.ResourceOwnerUid, new PlayResource("uri", PreparingItem.AudioResource, PreparingItem.MetaData), "link");

            InvokeBeforeResourceStarted(this, e);
            InvokeAfterResourceStarted(this, e);
        }
Ejemplo n.º 5
0
 void server_PlayInfo(object sender, PlayInfoEventArgs e)
 {
     if (axWindowsMediaPlayer1.currentMedia != null)
     {
         e.Duration = axWindowsMediaPlayer1.currentMedia.duration;
     }
     e.Position = axWindowsMediaPlayer1.Ctlcontrols.currentPosition;
     e.Rate     = _rate;
 }
Ejemplo n.º 6
0
 public string ParseNowPlayingString(string input, PlayInfoEventArgs e)
 {
     return(input
            .Replace("{title}", e.ResourceData.ResourceTitle)
            .Replace("{invoker}", "[URL=client://" + e.Invoker.ClientId + "/" + e.Invoker.ClientUid + "]" + e.Invoker.NickName + "[/URL]")
            .Replace("{invokeruid}", e.Invoker.ClientUid)
            .Replace("{volume}", e.MetaData.Volume.ToString())
            .Replace("{resourceid}", e.ResourceData.ResourceId)
            .Replace("{uniqueid}", e.ResourceData.UniqueId)
            .Replace("{playuri}", e.PlayResource.PlayUri)
            .Replace("{length}", 2.0m.ToString(bot.PlayerConnection.Length.ToString())));
     // TODO: Length, etc
 }
Ejemplo n.º 7
0
        public E <LocalStr> StartResource(SongAnalyzerResult result)
        {
            var resource     = result.Resource;
            var restoredLink = result.RestoredLink.OkOr(null);

            var playInfo = new PlayInfoEventArgs(resource.Meta.ResourceOwnerUid, resource, restoredLink);

            BeforeResourceStarted?.Invoke(this, playInfo);

            var res = StartResource(resource);

            if (!res.Ok)
            {
                return(res);
            }

            AfterResourceStarted?.Invoke(this, playInfo);
            return(res);
        }
Ejemplo n.º 8
0
 protected void InvokeAfterResourceStarted(object sender, PlayInfoEventArgs e)
 {
     RemoveFinishedTask();
     AfterResourceStarted?.Invoke(sender, e);
 }
Ejemplo n.º 9
0
 protected void InvokeBeforeResourceStarted(object sender, PlayInfoEventArgs e)
 {
     BeforeResourceStarted?.Invoke(sender, e);
 }
Ejemplo n.º 10
0
        public void RunStartSongTaskTest()
        {
            var lck              = new object();
            var queueItem        = new QueueItem(Constants.Resource1AYoutube, new MetaData(Constants.TestUid, Constants.ListId));
            var queueItemGain    = new QueueItem(Constants.Resource1AYoutubeGain, new MetaData(Constants.TestUid, Constants.ListId));
            var playResource     = new PlayResource(queueItem.AudioResource.ResourceId, queueItem.AudioResource, queueItem.MetaData);
            var playResourceGain = new PlayResource(queueItemGain.AudioResource.ResourceId, queueItemGain.AudioResource, queueItemGain.MetaData);

            {
                // Queue item without gain gets it set and update gets invoked
                var loaderContext = new LoaderContextMock();
                var player        = new PlayerMock();

                var task = new StartSongTask(loaderContext, player, Constants.VolumeConfig, lck, queueItem);

                AudioResource changedResource     = null;
                QueueItem     containingQueueItem = null;
                task.OnAudioResourceUpdated += (sender, args) => {
                    changedResource     = args.Resource;
                    containingQueueItem = args.QueueItem;
                };

                var waitHandle  = new InformingEventWaitHandle(false, EventResetMode.AutoReset);
                var tokenSource = new CancellationTokenSource();
                var t           = Task.Run(() => task.RunInternal(waitHandle, tokenSource.Token));

                // Wait that the task reached the first point, cancel
                waitHandle.OutputHandle.WaitOne();
                tokenSource.Cancel();
                waitHandle.Set();

                // Check that it actually failed
                AssertThrowsInnerException <AggregateException, TaskCanceledException>(() => {
                    var _ = t.Result;
                });

                Assert.NotNull(changedResource);
                Assert.NotNull(containingQueueItem);
                Assert.AreSame(containingQueueItem, queueItem);

                var gain = changedResource.Gain;
                Assert.IsTrue(gain.HasValue);
                Assert.AreEqual(gain.Value, VolumeDetectorMock.VolumeSet);
            }

            {
                var loaderContext = new LoaderContextMock();
                var player        = new PlayerMock();

                var task = new StartSongTask(loaderContext, player, Constants.VolumeConfig, lck, queueItem);

                var waitHandle  = new InformingEventWaitHandle(false, EventResetMode.AutoReset);
                var tokenSource = new CancellationTokenSource();
                var t           = Task.Run(() => task.RunInternal(waitHandle, tokenSource.Token));

                // Wait that the task reached the first point, cancel
                waitHandle.OutputHandle.WaitOne();
                lock (lck) {
                    waitHandle.Set();
                    Task.Delay(100);
                    tokenSource.Cancel();
                }

                AssertThrowsInnerException <AggregateException, TaskCanceledException>(() => {
                    var _ = t.Result;
                });
            }

            {
                var player = new PlayerMock();

                var task = new StartSongTask(null, player, Constants.VolumeConfig, null, null);
                PlayInfoEventArgs argsBefore = null;
                PlayInfoEventArgs argsAfter  = null;

                task.BeforeResourceStarted += (sender, args) => {
                    Assert.IsNotNull(args);
                    Assert.AreEqual(args.Invoker, Constants.TestUid);
                    Assert.AreSame(args.MetaData, queueItemGain.MetaData);
                    Assert.AreSame(args.ResourceData, queueItemGain.AudioResource);
                    Assert.AreSame(args.SourceLink, LoaderContextMock.RestoredLink);
                    argsBefore = args;
                };

                task.AfterResourceStarted += (sender, args) => {
                    Assert.IsNotNull(args);
                    Assert.AreEqual(args.Invoker, Constants.TestUid);
                    Assert.AreSame(args.MetaData, queueItemGain.MetaData);
                    Assert.AreSame(args.ResourceData, queueItemGain.AudioResource);
                    Assert.AreSame(args.SourceLink, LoaderContextMock.RestoredLink);
                    argsAfter = args;
                };

                var t = Task.Run(() => task.StartResource(new SongAnalyzerResult {
                    Resource = playResourceGain, RestoredLink = LoaderContextMock.RestoredLink
                }));

                var res = t.Result;

                Assert.IsTrue(res.Ok);
                Assert.AreSame(argsBefore, argsAfter);

                Assert.NotNull(player.PlayArgs.res);
                Assert.NotNull(player.PlayArgs.gain);
                Assert.AreSame(player.PlayArgs.res, playResourceGain);
                Assert.AreEqual(player.PlayArgs.gain, queueItemGain.AudioResource.Gain);
                Assert.AreEqual(player.Volume, 10.0f);
            }

            {
                var player = new PlayerMock();

                var task = new StartSongTask(null, player, Constants.VolumeConfig, null, null);
                var t    = Task.Run(() => task.StartResource(new SongAnalyzerResult {
                    Resource = playResource, RestoredLink = LoaderContextMock.RestoredLink
                }));

                var res = t.Result;

                Assert.IsTrue(res.Ok);

                Assert.NotNull(player.PlayArgs.res);
                Assert.NotNull(player.PlayArgs.gain);
                Assert.AreSame(player.PlayArgs.res, playResource);
                Assert.AreEqual(player.PlayArgs.gain, 0);
                Assert.AreEqual(player.Volume, 10.0f);
            }
        }
Ejemplo n.º 11
0
 private void Audio_OnResourceStarted(object sender, PlayInfoEventArgs e)
 {
     // TODO: temporary fix till multithread dispatcher works
     try { InvokeEvent(); }
     catch (TimeoutException) { }
 }
Ejemplo n.º 12
0
        private void PlayManager_AfterResourceStarted(object sender, PlayInfoEventArgs e)
        {
            if (!Settings.Default.Enabled)
            {
                return;
            }
            PluginLog(Log.Level.Debug, "Track changed. Applying now playing values");
            if (!string.IsNullOrWhiteSpace(Settings.Default.Description))
            {
                try {
                    bot.QueryConnection.ChangeDescription(ParseNowPlayingString(Settings.Default.Description, e));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to change Description: " + ex.Message); }
            }
            if (!string.IsNullOrWhiteSpace(Settings.Default.ServerChat))
            {
                try {
                    bot.QueryConnection.SendServerMessage(ParseNowPlayingString(Settings.Default.ServerChat, e));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to send Server Message: " + ex.Message); }
            }
            if (!string.IsNullOrWhiteSpace(Settings.Default.ChannelChat))
            {
                try {
                    bot.QueryConnection.SendChannelMessage(ParseNowPlayingString(Settings.Default.ChannelChat, e));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to send Channel Message: " + ex.Message); }
            }
            if (!string.IsNullOrWhiteSpace(Settings.Default.PrivateChat))
            {
                try {
                    var clientbuffer = lib.ClientList(ClientListOptions.uid).ToList();
                    foreach (var client in clientbuffer)
                    {
                        foreach (var uid in Settings.Default.PrivateChatUIDs)
                        {
                            if (client.Uid == uid)
                            {
                                bot.QueryConnection.SendMessage(ParseNowPlayingString(Settings.Default.PrivateChat, e), client.ClientId);
                            }
                        }
                    }
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to send private Message: " + ex.Message); }
            }
            if (!string.IsNullOrWhiteSpace(Settings.Default.NickName))
            {
                try {
                    bot.QueryConnection.ChangeName(ParseNowPlayingString(Settings.Default.NickName, e));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to change nickname: " + ex.Message); }
            }
            if (!string.IsNullOrWhiteSpace(Settings.Default.PluginCommand))
            {
                try {
                    lib.Send("plugincmd", new CommandParameter("name", "TS3AudioBot"),
                             new CommandParameter("targetmode", 0),
                             new CommandParameter("data", ParseNowPlayingString(Settings.Default.PluginCommand, e)));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to send Plugin Command: " + ex.Message); }
            }
            if (!string.IsNullOrWhiteSpace(Settings.Default.MetaData))
            {
                try {
                    /* TODO: Append Meta Data
                     * var clid = lib.ClientId;
                     * var ownClient = lib.Send<ClientData>("clientinfo", new CommandParameter("clid", clid)).FirstOrDefault();
                     * ownClient.*/
                    lib.Send("clientupdate", new CommandParameter("client_meta_data", ParseNowPlayingString(Settings.Default.MetaData, e)));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to set Meta Data: " + ex.Message); }
            }
            var ownChannelId = lib.WhoAmI().ChannelId;

            if (!string.IsNullOrWhiteSpace(Settings.Default.ChannelName))
            {
                try {
                    lib.Send("channeledit", new CommandParameter("cid", ownChannelId),
                             new CommandParameter("channel_name", ParseNowPlayingString(Settings.Default.ChannelName, e)));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to set channel name: " + ex.Message); }
            }
            if (!string.IsNullOrWhiteSpace(Settings.Default.ChannelTopic))
            {
                try {
                    lib.Send("channeledit", new CommandParameter("cid", ownChannelId),
                             new CommandParameter("channel_topic", ParseNowPlayingString(Settings.Default.ChannelTopic, e)));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to set channel topic: " + ex.Message); }
            }
            if (!string.IsNullOrWhiteSpace(Settings.Default.ChannelDescription))
            {
                try {
                    lib.Send("channeledit", new CommandParameter("cid", ownChannelId),
                             new CommandParameter("channel_description", ParseNowPlayingString(Settings.Default.ChannelDescription, e)));
                } catch (Exception ex) { PluginLog(Log.Level.Warning, "Exeption thrown while trying to set channel description: " + ex.Message); }
            }
        }