Ejemplo n.º 1
0
 /// <summary>
 /// Prüft ob IsZoneCord gesetzt ist
 /// Falls nicht FallBack auf Zonen
 /// Falls Player in einer Zone ist, wird dieser aus dieser Rausgenommen.
 /// </summary>
 /// <param name="sp">Player der geprüft werden soll.</param>
 /// <param name="fromMessaQueue">Is the Call from MesseageQueue</param>
 /// <returns></returns>
 public static Boolean CheckIsZoneCord(SonosPlayer sp, Boolean fromMessaQueue = false)
 {
     try
     {
         if (sp.IsZoneCoord == false)
         {
             sp.BecomeCoordinatorofStandaloneGroup();
             Thread.Sleep(200);
             return(false);
         }
         if (sp.IsZoneCoord == null)
         {
             //Wenn IsZoneCoord Null und keine Zone gefunden wurde, dann ist der Player in einer Gruppe.
             var sz = GetZone(sp.Name);
             if (sz == null)
             {
                 sp.IsZoneCoord = false;
                 sp.BecomeCoordinatorofStandaloneGroup();
                 Thread.Sleep(200);
                 return(false);
             }
             sp.IsZoneCoord = true;
         }
         return(true);
     }
     catch (Exception ex)
     {
         ServerErrorsAdd("CheckIsZoneCord bei Player:" + sp.Name, ex);
         return(true);
     }
 }
Ejemplo n.º 2
0
        public string Dash5(string id)
        {
            const string rsh = "x-sonosapi-stream:s18353?sid=254&flags=8224&sn=0";

            try
            {
                SonosPlayer primaryplayer         = SonosHelper.GetPlayer(primaryPlayerName);
                SonosPlayer secondaryplayer       = SonosHelper.GetPlayer(SonosConstants.KücheName);
                ushort      secondaryPlayerVolume = SonosConstants.KücheVolume;
                SonosPlayer thirdplayer           = SonosHelper.GetPlayer(SonosConstants.EsszimmerName);
                ushort      thirdPlayerVolume     = SonosConstants.EsszimmerVolume;
                var         aktUri = primaryplayer.GetMediaInfoURIMeta()[0];
                //scheint schon dash5 gedrückt worden zu sein.
                if (aktUri == rsh)
                {
                    if (primaryplayer.CurrentState.TransportState == PlayerStatus.PLAYING)
                    {
                        //ausschalten
                        primaryplayer.SetPause();
                        //Daten vom Marantz ermitteln
                        if (Marantz.Initialisieren(SonosConstants.MarantzUrl))
                        {
                            if (Marantz.SelectedInput == MarantzInputs.Sonos && Marantz.PowerOn)
                            {
                                Marantz.PowerOn = false;
                            }
                        }
                        return(retValok + " RSH ausgeschaltet.");
                    }

                    //Daten vom Marantz ermitteln
                    if (Marantz.Initialisieren(SonosConstants.MarantzUrl))
                    {
                        if (Marantz.SelectedInput != MarantzInputs.Sonos || !Marantz.PowerOn)
                        {
                            if (Marantz.PowerOn)
                            {
                                Marantz.SelectedInput = MarantzInputs.Sonos;
                            }
                            else
                            {
                                Marantz.PowerOn = true;
                            }
                            if (Marantz.SelectedInput != MarantzInputs.Sonos)
                            {
                                Marantz.SelectedInput = MarantzInputs.Sonos;
                            }
                        }
                    }
                    primaryplayer.SetPlay();
                    return(retValok + " RSH eingeschaltet.");
                }
                try
                {
                    //ab hier alles neu
                    var primaryZone = SonosHelper.GetZone(primaryPlayerName);
                    if (primaryZone != null && primaryZone.Players.Count == 2 && primaryZone.Players.Contains(thirdplayer) && primaryZone.Players.Contains(secondaryplayer))
                    {
                    }
                    else
                    {
                        if (primaryZone == null)
                        {
                            primaryplayer.BecomeCoordinatorofStandaloneGroup();
                            Thread.Sleep(200);
                            secondaryplayer.SetAVTransportURI(SonosConstants.xrincon + primaryplayer.UUID);
                            Thread.Sleep(300);
                            thirdplayer.SetAVTransportURI(SonosConstants.xrincon + primaryplayer.UUID);
                            Thread.Sleep(300);
                            if (secondaryplayer.GetVolume() != secondaryPlayerVolume)
                            {
                                secondaryplayer.SetVolume(secondaryPlayerVolume);
                            }
                            if (thirdplayer.GetVolume() != thirdPlayerVolume)
                            {
                                thirdplayer.SetVolume(thirdPlayerVolume);
                            }
                        }
                        else
                        {
                            if (!primaryZone.Players.Contains(secondaryplayer))
                            {
                                secondaryplayer.SetAVTransportURI(SonosConstants.xrincon + primaryplayer.UUID);
                                Thread.Sleep(300);
                                if (secondaryplayer.GetVolume() != secondaryPlayerVolume)
                                {
                                    secondaryplayer.SetVolume(secondaryPlayerVolume);
                                }
                            }
                            if (!primaryZone.Players.Contains(thirdplayer))
                            {
                                thirdplayer.SetAVTransportURI(SonosConstants.xrincon + primaryplayer.UUID);
                                Thread.Sleep(300);
                                if (thirdplayer.GetVolume() != thirdPlayerVolume)
                                {
                                    thirdplayer.SetVolume(thirdPlayerVolume);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return("Dash5:Block1:" + ex.Message);
                }
                try
                {
                    //Daten vom Marantz ermitteln
                    if (Marantz.Initialisieren(SonosConstants.MarantzUrl))
                    {
                        if (Marantz.SelectedInput != MarantzInputs.Sonos || !Marantz.PowerOn)
                        {
                            if (Marantz.PowerOn)
                            {
                                Marantz.SelectedInput = MarantzInputs.Sonos;
                            }
                            else
                            {
                                Marantz.PowerOn = true;
                            }
                            if (Marantz.SelectedInput != MarantzInputs.Sonos)
                            {
                                Marantz.SelectedInput = MarantzInputs.Sonos;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return("Dash5:Block2:" + ex.Message);
                }

                if (primaryplayer.GetVolume() != primaryplayerVolume)
                {
                    primaryplayer.SetVolume(primaryplayerVolume);
                }
                if (aktUri != rsh)
                {
                    primaryplayer.SetAVTransportURI(rsh, "<DIDL-Lite xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\" xmlns:r=\"urn:schemas-rinconnetworks-com:metadata-1-0/\" xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\"><item id=\"F00092020s18353\" parentID=\"F00082064y1%3apopular\" restricted=\"true\"><dc:title>R.SH</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id=\"cdudn\" nameSpace=\"urn:schemas-rinconnetworks-com:metadata-1-0/\">SA_RINCON65031_</desc></item></DIDL-Lite>");
                    Thread.Sleep(300);
                }
                primaryplayer.SetPlay();
                return(retValok + " eingeschaltet und RSH gestartet");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public string Dash2(int id)
        {
            //Durch alle Zonen gehen und Gruppen auflösen und Pausieren, falls einer abspielt.

            #region STOPP

            Boolean foundplayed = false;
            //List<string> foundedPlayer = new List<string>();
            try
            {
                try
                {
                    if (SonosHelper.Sonos == null)
                    {
                        SonosHelper.Initialisierung();
                    }
                    if (SonosHelper.Sonos == null)
                    {
                        return(retValReload + " Sonos ist null und konnte nicht initialisiert werden!");
                    }
                    lock (SonosHelper.Sonos.Zones)
                    {
                        foreach (SonosZone sp in SonosHelper.Sonos.Zones)
                        {
                            try
                            {
                                if (sp.Coordinator.CurrentState.TransportState == PlayerStatus.PLAYING)
                                {
                                    foundplayed = true;
                                    sp.Coordinator.SetPause();
                                }
                            }
                            catch (Exception ex)
                            {
                                return(retValReload + "Block1.1 Exception: Beim prüfen ob ausgeschaltet werden muss:" +
                                       ex.Message);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(retValReload + "Block1 Exception: Beim prüfen ob ausgeschaltet werden muss:" + ex.Message);
                }
            }
            catch (Exception ex)
            {
                return(retValReload + " Exception: Beim prüfen ob ausgeschaltet werden muss:" + ex.Message);
            }

            if (foundplayed)
            {
                try
                {
                    Task.Factory.StartNew(DashHelper.PowerOffMarantz);
                }
                catch
                {
                    return(retValReload + " Exception: Marantz konnte nicht geschaltet werden. ");
                }
                try
                {
                    Task.Factory.StartNew(DashHelper.PowerOffAruroras);
                }
                catch (Exception ex)
                {
                    return(retValReload + "exception: Aurora konnten nicht ausgeschaltet werden. " + ex.Message);
                }
                try
                {
                    SonosPlayer primaryplayer         = SonosHelper.GetPlayer(primaryPlayerName);
                    SonosPlayer secondaryplayer       = SonosHelper.GetPlayer(SonosConstants.EsszimmerName);
                    SonosPlayer thirdplayer           = SonosHelper.GetPlayer(SonosConstants.KücheName);
                    ushort      secondaryplayerVolume = SonosConstants.EsszimmerVolume;
                    ushort      thirdplayerVolume     = SonosConstants.KücheVolume;
                    if (secondaryplayer.GetVolume() != secondaryplayerVolume)
                    {
                        secondaryplayer.SetVolume(secondaryplayerVolume);
                    }
                    if (primaryplayer.GetVolume() != primaryplayerVolume)
                    {
                        primaryplayer.SetVolume(primaryplayerVolume);
                    }
                    if (thirdplayer.GetVolume() != thirdplayerVolume)
                    {
                        thirdplayer.SetVolume(thirdplayerVolume);
                    }
                }
                catch (Exception ex)
                {
                    return(retValReload + "Lautstärke resetet mit Fehler: " + ex.Message);
                }
                return("ok, Musik wurde ausgeschaltet.");
            }

            #endregion STOPP
            #region Start Devices
            try
            {
                //Aurora einschalten zwischen 18 Uhr und 5 Uhr oder immer Oktober bsi März
                //if (DateTime.Now.Hour > 17 || DateTime.Now.Hour < 6 || DateTime.Now.Month > 9 || DateTime.Now.Month < 4)
                //{
                Task.Factory.StartNew(DashHelper.PowerOnAruroras);
                //}
            }
            catch (Exception ex)
            {
                return(retValReload + "exception: Aurora konnten nicht eingeschaltet werden. " + ex.Message);
            }
            try
            {
                //Marantz Verarbeiten.
                Task.Factory.StartNew(DashHelper.PowerOnMarantz);
            }
            catch (Exception ex)
            {
                return(retValReload + " Exception beim Marantz: " + ex.Message);
            }
            #endregion Start Devices
            try
            {
                //Alles ins Wohnzimmer legen.
                SonosPlayer primaryplayer   = SonosHelper.GetPlayer(primaryPlayerName);
                SonosPlayer secondaryplayer = SonosHelper.GetPlayer(SonosConstants.EsszimmerName);
                SonosPlayer thirdplayer     = SonosHelper.GetPlayer(SonosConstants.KücheName);
                if (DashHelper.IsSonosTargetGroupExist(primaryplayer, new List <SonosPlayer> {
                    secondaryplayer, thirdplayer
                }))
                {
                    //Die Zielarchitektur existiert, daher keine Lautstärkesondern nur Playlist
                    int     oldcurrenttrack = primaryplayer.GetAktSongInfo().TrackIndex;
                    var     playlists       = GetAllPlaylist();
                    var     playlist        = playlists.FirstOrDefault(x => x.Title.ToLower() == defaultPlaylist.ToLower());
                    Boolean loadPlaylist    = false;
                    if (playlist != null)
                    {
                        loadPlaylist = DashHelper.CheckPlaylist(playlist.ContainerID, primaryplayer);
                    }
                    if (loadPlaylist)
                    {
                        if (!DashHelper.LoadPlaylist(playlist, primaryplayer))
                        {
                            return("reload, weil Playlist nicht geladen werden konnte");
                        }
                    }
                    else
                    {
                        //alten Song aus der Playlist laden, da immer wieder auf 1 reset passiert.
                        primaryplayer.SetTrackInPlaylist(oldcurrenttrack.ToString());
                        Thread.Sleep(100);
                    }
                    ushort secondaryplayerVolume = SonosConstants.EsszimmerVolume;
                    ushort thirdplayerVolume     = SonosConstants.KücheVolume;
                    if (secondaryplayer.GetVolume() != secondaryplayerVolume)
                    {
                        secondaryplayer.SetVolume(secondaryplayerVolume);
                    }
                    if (primaryplayer.GetVolume() != primaryplayerVolume)
                    {
                        primaryplayer.SetVolume(primaryplayerVolume);
                    }
                    if (thirdplayer.GetVolume() != thirdplayerVolume)
                    {
                        thirdplayer.SetVolume(thirdplayerVolume);
                    }
                }
                else
                {
                    //alles neu
                    try
                    {
                        primaryplayer.BecomeCoordinatorofStandaloneGroup();
                        Thread.Sleep(500);
                        secondaryplayer.SetAVTransportURI(SonosConstants.xrincon + primaryplayer.UUID);
                        Thread.Sleep(300);
                        thirdplayer.SetAVTransportURI(SonosConstants.xrincon + primaryplayer.UUID);
                        Thread.Sleep(300);
                    }
                    catch (Exception ex)
                    {
                        return(retValReload + " Exception beim Gruppenauflösen: " + ex.Message);
                    }
                    try
                    {
                        ushort secondaryplayerVolume = SonosConstants.EsszimmerVolume;
                        ushort thirdplayerVolume     = SonosConstants.KücheVolume;
                        if (secondaryplayer.GetVolume() != secondaryplayerVolume)
                        {
                            secondaryplayer.SetVolume(secondaryplayerVolume);
                        }
                        if (primaryplayer.GetVolume() != primaryplayerVolume)
                        {
                            primaryplayer.SetVolume(primaryplayerVolume);
                        }
                        if (thirdplayer.GetVolume() != thirdplayerVolume)
                        {
                            thirdplayer.SetVolume(thirdplayerVolume);
                        }
                    }
                    catch (Exception ex)
                    {
                        return(retValReload + " Exception beim Lautstärke setzen: " + ex.Message);
                    }
                    try
                    {
                        //Playlist verarveiten
                        var playlists = GetAllPlaylist();
                        var playlist  = playlists.FirstOrDefault(x => x.Title.ToLower() == defaultPlaylist.ToLower());
                        if (!DashHelper.LoadPlaylist(playlist, primaryplayer))
                        {
                            return("reload, weil Playlist nicht geladen werden konnte");
                        }
                    }
                    catch (Exception ex)
                    {
                        return(retValReload + " Exception beim Playlist setzen: " + ex.Message);
                    }
                }
                try
                {
                    primaryplayer.SetPlay();
                }
                catch (Exception ex)
                {
                    return(retValReload + " Exception beim Starten der Wiedergabe: " + ex.Message);
                }
            }
            catch (Exception ex)
            {
                return(retValReload + "exception: Großer Block nicht abgefangen: " + ex.Message);
            }

            return(retValok);
        }