Exemplo n.º 1
0
        private void playRadio()
        {
            try
            {
                Item selectedItem = (Item)stationList.SelectedItem;
                setStationIndex(stationList.SelectedIndex);
                stopRadio();
                setPlayerStatus(false);
                StatusLabel.Text          = "Chargement...";
                progressBar.Visible       = true;
                stationLogo.SizeMode      = PictureBoxSizeMode.StretchImage;
                stationLogo.BorderStyle   = BorderStyle.Fixed3D;
                stationLogo.ImageLocation = selectedItem.Stream.uriLogo.Uri.ToString();

                mediaPlayer.Open(selectedItem.Stream.uriListen.Uri);
                mediaPlayer.Play();
                mediaPlayer.Volume = (double)(volumeControl.Value / 100.0);
                this.Text          = selectedItem.ToString();
            }
            catch (Exception ex)
            {
                setPlayerStatus(true);
                progressBar.Visible = false;
                StatusLabel.Text    = "Erreur de lecture...";

                using (eventLogger ev = new eventLogger("itumRadio"))
                {
                    ev.writeLog(String.Format("Exception in playRadio:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
                }
            }
        }
Exemplo n.º 2
0
 private void ItumRadio_FormClosing(object sender, FormClosingEventArgs e)
 {
     using (eventLogger ev = new eventLogger("itumRadio"))
     {
         ev.writeLog("Fin normale de l'application", System.Diagnostics.EventLogEntryType.Information);
     }
 }
Exemplo n.º 3
0
 private void BufferingStarted_Event(object sender, System.EventArgs e)
 {
     try
     {
         setPlayerStatus(false);
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in BufferingStarted_Event:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 4
0
 private void playButton_Click(object sender, EventArgs e)
 {
     try
     {
         playRadio();
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in playButton_Click:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 5
0
 private void stationList_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         playRadio();
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in stationList_SelectedIndexChanged:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 6
0
        public ItumRadio()
        {
            try
            {
                Int32 i = 0;

                this.Icon = itumRadio.Properties.Resources.ItumRadio;
                InitializeComponent();
                iceCast2 = new IceCast2("http://radio.conseil.itum.net:8000/");
                volumeControl.Minimum     = 0;
                volumeControl.Maximum     = 100;
                volumeControl.SmallChange = 1;
                volumeControl.LargeChange = 10;
                volumeControl.Value       = getVolumeIndex();

                mediaPlayer.BufferingEnded   += new System.EventHandler(BufferingEnded_Event);
                mediaPlayer.BufferingStarted += new System.EventHandler(BufferingStarted_Event);
                mediaPlayer.MediaOpened      += new System.EventHandler(MediaOpened_Event);

                foreach (IceCast2.StreamInfo stream in iceCast2.streamInfoList)
                {
                    stationList.Items.Add(new Item(stream, i++));
                }

                if (getStationIndex() == -1)
                {
                    stationList.SelectedIndex = stationList.FindString(Properties.Settings.Default.defaultStation);
                }
                else
                {
                    stationList.SelectedIndex = getStationIndex();
                }

                using (eventLogger ev = new eventLogger("itumRadio"))
                {
                    ev.writeLog("Démarrage de l'application", System.Diagnostics.EventLogEntryType.Information);
                }
            }
            catch (Exception ex)
            {
                using (eventLogger ev = new eventLogger("itumRadio"))
                {
                    ev.writeLog(String.Format("Exception in ItumRadio:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
                }

                MessageBox.Show("Une erreur est survenue.", "itumRadio", MessageBoxButtons.OK, MessageBoxIcon.Error);
                exitApplication(1);
            }
        }
Exemplo n.º 7
0
 private void volumeControl_Scroll(object sender, EventArgs e)
 {
     try
     {
         setVolumeIndex(volumeControl.Value);
         mediaPlayer.Volume = (double)(volumeControl.Value / 100.0);
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in volumeControl_Scroll:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 8
0
 public override string ToString()
 {
     try
     {
         return(Stream.streamName + ", " + Stream.streamCity + " - " + Stream.streamDescription);
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in Item.ToString:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
         return(String.Empty);
     }
 }
Exemplo n.º 9
0
 private void stopRadio()
 {
     try
     {
         mediaPlayer.Stop();
         mediaPlayer.Close();
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in stopRadio:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 10
0
 public Item(IceCast2.StreamInfo stream, int value)
 {
     try
     {
         Stream = stream;
         Value  = value;
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in Item:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 11
0
 private void exitApplication(Int32 ErrorLevel = 0)
 {
     if (Application.MessageLoop)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog("Fin de l'application", System.Diagnostics.EventLogEntryType.Information);
         }
         Application.Exit();
     }
     else
     {
         Environment.Exit(ErrorLevel);
     }
 }
Exemplo n.º 12
0
 public void setStationIndex(Int32 Index)
 {
     try
     {
         Properties.UserSettings.Default.stationIndex = Index;
         Properties.UserSettings.Default.Save();
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in setStationIndex:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 13
0
 private void BufferingEnded_Event(object sender, System.EventArgs e)
 {
     try
     {
         setPlayerStatus(true);
         progressBar.Visible = false;
         StatusLabel.Text    = "Lecture";
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in BufferingEnded_Event:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 14
0
        public Int32 getStationIndex()
        {
            try
            {
                return(Properties.UserSettings.Default.stationIndex);
            }
            catch (Exception ex)
            {
                using (eventLogger ev = new eventLogger("itumRadio"))
                {
                    ev.writeLog(String.Format("Exception in getStationIndex:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
                }

                return(0);
            }
        }
Exemplo n.º 15
0
 private void stopButton_Click(object sender, EventArgs e)
 {
     try
     {
         stopRadio();
         setPlayerStatus(true);
         progressBar.Visible = false;
         StatusLabel.Text    = String.Empty;
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in stopButton_Click:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 16
0
 private void setPlayerStatus(Boolean Status)
 {
     try
     {
         playButton.Enabled = Status;
         //stopButtonbutton.Enabled = Status;
         forwardButton.Enabled = Status;
         reverseButton.Enabled = Status;
         stationList.Enabled   = Status;
         volumeControl.Enabled = Status;
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in setPlayerStatus:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 17
0
 private void reverseButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (stationList.SelectedIndex == 0)
         {
             stationList.SelectedIndex = stationList.Items.Count - 1;
         }
         else
         {
             stationList.SelectedIndex--;
         }
     }
     catch (Exception ex)
     {
         using (eventLogger ev = new eventLogger("itumRadio"))
         {
             ev.writeLog(String.Format("Exception in reverseButton_Click:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
         }
     }
 }
Exemplo n.º 18
0
        private static string DecodeFromUtf8(string utf8String)
        {
            try
            {
                byte[] utf8Bytes = new byte[utf8String.Length];
                for (int i = 0; i < utf8String.Length; ++i)
                {
                    utf8Bytes[i] = (byte)utf8String[i];
                }

                return(Encoding.UTF8.GetString(utf8Bytes, 0, utf8Bytes.Length));
            }
            catch (Exception ex)
            {
                using (eventLogger ev = new eventLogger("itumRadio"))
                {
                    ev.writeLog(String.Format("Exception in DecodeFromUtf8:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
                }

                return(null);
            }
        }
Exemplo n.º 19
0
        private String[] getResponseData(System.Net.WebHeaderCollection responseHeaders, String Key)
        {
            try
            {
                if (responseHeaders.GetValues(Key) != null)
                {
                    return(responseHeaders.GetValues(Key));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                using (eventLogger ev = new eventLogger("itumRadio"))
                {
                    ev.writeLog(String.Format("Exception in getResponseData:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
                }

                return(null);
            }
        }
Exemplo n.º 20
0
        private String getResponseData(System.Net.WebHeaderCollection responseHeaders, String Key, Int32 Id)
        {
            try
            {
                String[] data = getResponseData(responseHeaders, Key);

                if (data != null)
                {
                    return(DecodeFromUtf8(data[Id]));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                using (eventLogger ev = new eventLogger("itumRadio"))
                {
                    ev.writeLog(String.Format("Exception in getResponseData:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
                }
                return(null);
            }
        }
Exemplo n.º 21
0
        public IceCast2(String serverURL)
        {
            try
            {
                using (var webClient = new System.Net.WebClient())
                {
                    serverInfo         = new UriBuilder(serverURL);
                    webClient.Encoding = Encoding.UTF8;
                    serverInfo.Path    = @"/status-json.xsl";
                    iceData            = JsonConvert.DeserializeObject <IceData>(webClient.DownloadString(serverInfo.Uri));
                    System.Net.WebHeaderCollection responseHeaders = webClient.ResponseHeaders;
                    foreach (Source iceCastSources in iceData.icestats.source)
                    {
                        StreamInfo streamInfo = new StreamInfo();
                        streamInfo.uriListen  = new UriBuilder(iceCastSources.listenurl);
                        streamInfo.mountpoint = iceCastSources.listenurl.Split('/').Last().ToLower();

                        if (getResponseData(responseHeaders, streamInfo.mountpoint + @"-description", 0) != null)
                        {
                            streamInfo.streamDescription = getResponseData(responseHeaders, streamInfo.mountpoint + @"-description", 0);
                        }
                        else if (iceCastSources.server_description != String.Empty)
                        {
                            streamInfo.streamDescription = iceCastSources.server_description;
                        }
                        else
                        {
                            streamInfo.streamDescription = "Aucune Description";
                        }

                        if (getResponseData(responseHeaders, streamInfo.mountpoint + @"-name", 0) != null)
                        {
                            streamInfo.streamName = getResponseData(responseHeaders, streamInfo.mountpoint + @"-name", 0);
                        }
                        else if (iceCastSources.server_name != String.Empty)
                        {
                            streamInfo.streamName = iceCastSources.server_name;
                        }
                        else
                        {
                            streamInfo.streamName = streamInfo.mountpoint.ToUpper();
                        }

                        if (getResponseData(responseHeaders, streamInfo.mountpoint + @"-city", 0) != null)
                        {
                            streamInfo.streamCity = getResponseData(responseHeaders, streamInfo.mountpoint + @"-city", 0);
                        }
                        else
                        {
                            streamInfo.streamCity = String.Empty;
                        }

                        if (getResponseData(responseHeaders, streamInfo.mountpoint + @"-logo", 0) != null)
                        {
                            String s = getResponseData(responseHeaders, streamInfo.mountpoint + @"-logo", 0);
                            if (s.IndexOf(@"://") > -1)
                            {
                                streamInfo.uriLogo = new UriBuilder(s);
                            }
                            else
                            {
                                streamInfo.uriLogo      = new UriBuilder(serverInfo.Uri);
                                streamInfo.uriLogo.Path = s;
                            }
                        }
                        else
                        {
                            streamInfo.uriLogo = null;
                        }
                        streamInfoList.Add(streamInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                iceData        = null;
                streamInfoList = null;
                serverInfo     = null;

                using (eventLogger ev = new eventLogger("itumRadio"))
                {
                    ev.writeLog(String.Format("Exception in IceCast2:\n\n{0}", ex.ToString()), System.Diagnostics.EventLogEntryType.Error);
                }
            }
        }