/// <summary> /// Baut Cover, Titel und Artist fpr Radio Sender auf. /// </summary> /// <param name="si"></param> /// <param name="pl"></param> /// <returns></returns> private static SonosItem GetStreamRadioStuff(SonosItem si, SonosPlayer pl) { try { try { if (si.Title.StartsWith(xsonosapi) || si.Title == "Playlist" || !CheckRadioTitle(si.Title)) { si.Title = String.Empty; } if (CheckRadioTitle(si.StreamContent)) { si.Title = si.StreamContent; } si.StreamContent = radio; } catch (Exception ex) { pl.ServerErrorsAdd("SonosItemHelper:GetStreamRadioStuff:Block1 ", ex); } List <string> k = new List <string>(); try { k = pl.GetMediaInfoURIMeta(); if (k.Count != 0) { si.AlbumArtURI = "/getaa?s=1&u=" + k[0]; } } catch (Exception ex) { pl.ServerErrorsAdd("SonosItemHelper:GetStreamRadioStuff:Block2:CoverArt ", ex); } try { if (k.Count > 0 && k.ElementAtOrDefault(2) != null && !string.IsNullOrEmpty(k[2])) { SonosItem streaminfo = SonosItem.ParseSingleItem(pl.GetAktSongInfo().TrackMetaData); var x = SonosItem.ParseSingleItem(k[2]); si.Artist = x.Title; if (CheckRadioTitle(streaminfo.StreamContent)) { si.Title = streaminfo.StreamContent.Contains("|") ? streaminfo.StreamContent.Split('|')[0] : streaminfo.StreamContent; } } } catch (Exception ex) { pl.ServerErrorsAdd("SonosItemHelper:GetStreamRadioStuff:Block3:Anzahl K:" + k.Count, ex); } } catch (Exception ex) { pl.ServerErrorsAdd("SonosItemHelper:GetStreamRadioStuff ", ex); } return(si); }
/// <summary> /// Prüft die übergebene Playlist mit dem Übergeben Player ob neu geladen werden muss. /// </summary> /// <param name="pl">Playliste, die geladen werden soll.</param> /// <param name="sp">Coordinator aus der Führenden Zone</param> /// <returns>True muss neu geladen werden</returns> public static Boolean CheckPlaylist(string pl, SonosPlayer sp) { try { Boolean retval = false; var evtlStream = sp.GetAktSongInfo(); if (SonosItemHelper.CheckItemForStreamingUriCheck(evtlStream.TrackURI)) { return(true); } var actpl = sp.GetPlaylist(0, 10); if (actpl.Count == 0) { return(true); } var toLoadpl = sp.BrowsingWithLimitResults(pl, 10); if (toLoadpl.Count == 0) { return(true); //eigentlich ein Fehler } for (int i = 0; i < actpl.Count; i++) { if (actpl[i].Title == toLoadpl[i].Title) { continue; } retval = true; break; } return(retval); } catch (Exception ex) { SonosHelper.ServerErrorsAdd("Dash2:CheckPlaylist", ex); return(true); } }
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); }