public async void MuteAndUnMute()
        {
            var info = await _mpcHomeCinema.GetInfo();

            if (info.Muted)
            {
                var res1 = await _mpcHomeCinema.UnMuteAsync();

                Assert.True(res1.ResultCode == ResultCode.Ok);
                Assert.False(res1.Info.Muted);
                var res2 = await _mpcHomeCinema.MuteAsync();

                Assert.True(res2.ResultCode == ResultCode.Ok);
                Assert.True(res2.Info.Muted);
            }
            else
            {
                var res2 = await _mpcHomeCinema.MuteAsync();

                Assert.True(res2.ResultCode == ResultCode.Ok);
                Assert.True(res2.Info.Muted);

                var res1 = await _mpcHomeCinema.UnMuteAsync();

                Assert.True(res1.ResultCode == ResultCode.Ok);
                Assert.False(res1.Info.Muted);
            }
        }
Ejemplo n.º 2
0
        public Info GetInfo()
        {
            Info info = null;

            Task.Run(async() =>
            {
                info = await player.GetInfo();
            }).GetAwaiter().GetResult();
            return(info);
        }
Ejemplo n.º 3
0
        public MPCController()
        {
            Console.WriteLine("[MPC] init");
            player         = new MPCHomeCinema(Settings.MPCWebUIAddress);
            updateInterval = new TimeSpan(0, 0, 1);

            // Wait connection
            Task.Run(async() =>
            {
                Console.WriteLine("[MPC] init GetInfo");
                var task = await player.GetInfo();
                Console.WriteLine(task.ToString());
                initialized?.Invoke(this, new EventArgs());
            }).GetAwaiter();

            /*
             * playerObserver = new MPCHomeCinemaObserver(player);
             * playerObserver.PropertyChanged += (sender, args) =>
             * {
             *  switch (args.Property)
             *  {
             *      case Property.File:
             *          Console.WriteLine($"Property changed from {args.OldInfo.FileName}, -> {args.NewInfo.FileName}");
             *          break;
             *      case Property.State:
             *          Console.WriteLine($"Property changed from {args.OldInfo.State}, -> {args.NewInfo.State}");
             *          break;
             *      case Property.Possition:
             *          Console.WriteLine($"Property changed from {args.OldInfo.Position}, -> {args.NewInfo.Position}");
             *          break;
             *      default:
             *          throw new ArgumentOutOfRangeException();
             *  }
             * };*/

            // Update normaly
            RunUpdate();
        }
        private async void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            //double confidence = Double.Parse((string)json.recognized[0].ToString());
            String command = (string)json.recognized[0].ToString();
            String movie   = (string)json.recognized[1].ToString();
            String number  = (string)json.recognized[2].ToString();
            String time    = (string)json.recognized[3].ToString();

            var info = await mpcHomeCinema.GetInfo();

            Console.WriteLine($"{info.FileName} is playing");
            Console.WriteLine($"{info.State} is its state");
            switch (command)
            {
            case "HELP":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    t.Speak("Hello. You can play or pause movie, change volume, mute or unmute, skip movie or play last one, skip or rewind given time stamp, or open new movie.");
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "PLAY":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.PlayAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "PAUSE":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.PauseAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "NEXT":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.NextAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "BACK":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.PrevAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "MOVEFWD":
                info = await mpcHomeCinema.GetInfo();

                if (movie == "EMP" && number != "EMP" && time != "EMP")
                {
                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        if (time == "HOUR")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours + int.Parse(number), info.Position.Minutes, info.Position.Seconds));
                        }
                        else if (time == "MINUTE")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours, info.Position.Minutes + int.Parse(number), info.Position.Seconds));
                        }
                        else if (time == "SECOND")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours, info.Position.Minutes, info.Position.Seconds + int.Parse(number)));
                        }
                    });
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "MOVEBWD":
                info = await mpcHomeCinema.GetInfo();

                if (movie == "EMP" && number != "EMP" && time != "EMP")
                {
                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        if (time == "HOUR")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours - int.Parse(number), info.Position.Minutes, info.Position.Seconds));
                        }
                        else if (time == "MINUTE")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours, info.Position.Minutes - int.Parse(number), info.Position.Seconds));
                        }
                        else if (time == "SECOND")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours, info.Position.Minutes, info.Position.Seconds - int.Parse(number)));
                        }
                    });
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "SETTIME":
                if (movie == "EMP" && number != "EMP" && time != "EMP")
                {
                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        if (time == "HOUR")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(int.Parse(number), 0, 0));
                        }
                        else if (time == "MINUTE")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(0, int.Parse(number), 0));
                        }
                        else if (time == "SECOND")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(0, 0, int.Parse(number)));
                        }
                    });
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "MUTE":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.MuteAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "UNMUTE":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.UnMuteAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "SETVOL":
                if (number == "EMP" && time != "EMP" && movie != "EMP")
                {
                    t.Speak("This command is forbidden");
                }
                else
                {
                    info = await mpcHomeCinema.GetInfo();

                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        await mpcHomeCinema.SetVolumeLevel(int.Parse(number));
                    });
                }
                break;

            case "VUP":
                info = await mpcHomeCinema.GetInfo();

                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    if (info.VolumeLevel <= 80)
                    {
                        await mpcHomeCinema.SetVolumeLevel(info.VolumeLevel + 20);
                    }
                    else
                    {
                        t.Speak("You can only increase volume by 20 points with this command. If you want to do it with custom number of points, please use set volume command,");
                    }
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "VDOWN":
                info = await mpcHomeCinema.GetInfo();

                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    if (info.VolumeLevel >= 20)
                    {
                        await mpcHomeCinema.SetVolumeLevel(info.VolumeLevel - 20);
                    }
                    else
                    {
                        t.Speak("You can only decrease volume by 20 points with this command. If you want to do it with custom number of points, please use set volume command,");
                    }
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "OPENFILE":
                if (movie == "EMP" || number != "EMP" || time != "EMP")
                {
                    t.Speak("This command is forbidden");
                }
                else
                {
                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        switch (movie)
                        {
                        case "ANIMALS":
                            await mpcHomeCinema.OpenFileAsync("C:\\Users\\Public\\Videos\\SampleVideos\\Animals.wmv");
                            break;

                        case "ODYSSEY":
                            await mpcHomeCinema.OpenFileAsync("C:\\Users\\Public\\Videos\\SampleVideos\\2001_ A SPACE ODYSSEY - Trailer.mp4");
                            break;

                        case "BLUEPLANET":
                            await mpcHomeCinema.OpenFileAsync("C:\\Users\\Public\\Videos\\SampleVideos\\Blue Planet II  The Prequel.wmv");
                            break;

                        case "PLANETEARTH":
                            await mpcHomeCinema.OpenFileAsync("C:\\Users\\Public\\Videos\\SampleVideos\\Planet Earth II Official Extended Trailer  BBC Earth.wmv");
                            break;
                        }
                    });
                }
                break;
            }
        }