예제 #1
0
 private void Stop_Function()
 {
     DLNA.DLNADevice Device = new DLNA.DLNADevice(DLNA.SSDP.Renderers[MediaRenderers.SelectedIndex]);
     if (Device.IsConnected())
     {
         Device.StopPlay();
         if (timer1.Enabled)
         {
             timer1.Stop();
         }
         TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "00:00:00"; });
         TrackDurationLabel.Invoke((MethodInvoker) delegate { TrackDurationLabel.Text = "00:00:00"; });
         trackProgress.Invoke((MethodInvoker) delegate { trackProgress.Maximum = 1; trackProgress.Value = 0; });
     }
 }
예제 #2
0
        private async void timer1_Tick(object sender, EventArgs e)
        {
            await Task.Run(() =>
            {
                MediaRenderers.Invoke((MethodInvoker) delegate
                {
                    if (MediaRenderers.SelectedIndex != -1)
                    {
                        DLNA.DLNADevice Device = new DLNA.DLNADevice(DLNA.SSDP.Renderers[MediaRenderers.SelectedIndex]);
                        if (Device.IsConnected())
                        {
                            string info   = Device.GetPosition();
                            string status = Device.GetTransportInfo();
                            string trackDurationString = info.ChopOffBefore("<TrackDuration>").Trim().ChopOffAfter("</TrackDuration>");
                            string trackPositionString = info.ChopOffBefore("<RelTime>").Trim().ChopOffAfter("</RelTime>");
                            string currentStatus       = status.ChopOffBefore("<CurrentTransportState>").Trim().ChopOffAfter("</CurrentTransportState>");
                            if (currentStatus != "TRANSITIONING")
                            {
                                if (!trackDurationString.Contains("HTTP"))
                                {
                                    if (trackDurationString.Contains(":") && trackPositionString.Contains(":"))
                                    {
                                        try
                                        {
                                            TimeSpan trackDurationTimeSpan = TimeSpan.Parse(trackDurationString);
                                            TimeSpan trackPositionTimeSpan = TimeSpan.Parse(trackPositionString);
                                            if (currentStatus == "PAUSED_PLAYBACK" && !paused)
                                            {
                                                paused = true;
                                                UpdatePauseText();
                                            }
                                            else if (currentStatus == "PLAYING")
                                            {
                                                paused = false;
                                                UpdatePauseText();
                                            }
                                            TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = trackPositionString; });
                                            if (Convert.ToInt32(trackDurationTimeSpan.TotalSeconds) != 0)
                                            {
                                                TrackDurationLabel.Invoke((MethodInvoker) delegate { TrackDurationLabel.Text = trackDurationString; });

                                                trackProgress.Invoke((MethodInvoker) delegate { trackProgress.Maximum = Convert.ToInt32(trackDurationTimeSpan.TotalSeconds); trackProgress.Value = Convert.ToInt32(trackPositionTimeSpan.TotalSeconds); });
                                                if (Convert.ToInt32(trackDurationTimeSpan.TotalSeconds) - Convert.ToInt32(trackPositionTimeSpan.TotalSeconds) <= 2)
                                                {
                                                    Thread.Sleep(2000);
                                                    timer1.Stop();
                                                    PlayNextTrack();
                                                }
                                            }
                                            else
                                            {
                                                TrackDurationLabel.Invoke((MethodInvoker) delegate { TrackDurationLabel.Text = ""; });
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }
                            else
                            {
                                TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Loading"; });
                            }
                        }
                    }
                });
            });
        }