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; }); } }
private void Stop_Function() { { if (MediaRenderers.SelectedIndex != -1) { DLNA.DLNADevice Device = new DLNA.DLNADevice(DLNA.SSDP.Renderers[MediaRenderers.SelectedIndex]); if (Device.IsConnected()) { Device.StopPlay(); if (timer1.Enabled) { timer1.Stop(); } } } } }
private string SendFile(DLNA.DLNADevice Device, int item, string url, string[] mediainfo = null) { string returnedvalue = Device.TryToPlayFile(url, mediainfo); if (!timer1.Enabled) { timer1.Start(); } if (MediaFiles.Items.Count - 1 > item) { if (MediaFileLocationType[item + 1] != 4 && MediaFileLocationType[item + 1] != 5) { Thread thread = new Thread(() => LoadNextTrack(trackNum + 1)); thread.Start(); return("OK"); } } return("OK"); }
private async void trackProgress_MouseUp(object sender, MouseEventArgs e) { if (MediaRenderers.SelectedIndex != -1) { await Task.Run(() => { { Invoke((MethodInvoker) delegate { TimeSpan positionToGo = positionToGo = TimeSpan.FromSeconds(trackProgress.Value); DLNA.DLNADevice Device = new DLNA.DLNADevice(DLNA.SSDP.Renderers[MediaRenderers.SelectedIndex]); if (Device.IsConnected()) { Device.Seek(string.Format("{0:c}", positionToGo)); } }); } }); } }
private void PauseTrack(bool updateTextOnly = false) { { if (MediaRenderers.SelectedIndex != -1) { DLNA.DLNADevice Device = new DLNA.DLNADevice(DLNA.SSDP.Renderers[MediaRenderers.SelectedIndex]); if (Device.IsConnected()) { if (paused) { Device.StartPlay(0); paused = false; UpdatePauseText(); } else { Device.Pause(); paused = true; UpdatePauseText(); } } } } }
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"; }); } } } }); }); }
private async void LoadFile(int item = 0) { string file_to_play = MediaFileLocation[item]; int location_type = MediaFileLocationType[item]; string filename = MediaFiles.Items[item].ToString(); if (MediaRenderers.SelectedIndex != -1) { DLNA.DLNADevice Device = new DLNA.DLNADevice(DLNA.SSDP.Renderers[MediaRenderers.SelectedIndex]); if (Device.IsConnected()) { if (timer1.Enabled) { timer1.Stop(); } Device.StopPlay(); MServer.FS = new MemoryStream(); if ((filename.EndsWith(".opus") && decodeOpusToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".flac") && decodeFLACToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".mp3") && decodeMP3ToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".m4a") && decodeM4AToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".wma") && decodeWMAToWAVToolStripMenuItem.Checked)) { MServer.Filename = Path.GetFileNameWithoutExtension(filename) + ".wav"; } else { MServer.Filename = filename; } string url = null; if (item != trackLoaded) { if (location_type == 1) //local file { mediainfo = await Extentions.getMetadata(file_to_play); int decodeMode = 0; if (file_to_play.EndsWith(".opus") && decodeOpusToWAVToolStripMenuItem.Checked) { decodeMode = 1; } else if (file_to_play.EndsWith(".flac") && decodeFLACToWAVToolStripMenuItem.Checked) { decodeMode = 2; } else if ((file_to_play.EndsWith(".mp3") && decodeMP3ToWAVToolStripMenuItem.Checked) || (file_to_play.EndsWith(".m4a") && decodeM4AToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".wma") && decodeWMAToWAVToolStripMenuItem.Checked)) { decodeMode = 3; } if (decodeMode != 0) { TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Decoding"; }); MServer.FS = await Extentions.decodeAudio(file_to_play, decodeMode); TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Ready"; }); } else { FileStream MediaFile = new FileStream(file_to_play, FileMode.Open); await MediaFile.CopyToAsync(MServer.FS); MediaFile.Close(); } } else if (location_type == 2) //Google Drive file (local download) { GDrive drive = GDriveForm.drive; TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Downloading"; }); await drive.DownloadFile(file_to_play, "tempfile"); TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Downloaded"; }); int decodeMode = 0; mediainfo = await Extentions.getMetadata("tempfile"); if (filename.EndsWith(".opus") && decodeOpusToWAVToolStripMenuItem.Checked) { decodeMode = 1; } else if (filename.EndsWith(".flac") && decodeFLACToWAVToolStripMenuItem.Checked) { decodeMode = 2; } else if ((filename.EndsWith(".mp3") && decodeMP3ToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".m4a") && decodeM4AToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".wma") && decodeWMAToWAVToolStripMenuItem.Checked)) { decodeMode = 3; } if (decodeMode != 0) { TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Decoding"; }); MServer.FS = await Extentions.decodeAudio("tempfile", decodeMode); TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Ready"; }); } File.Delete("tempfile"); } else if (location_type == 3) //CD Drive Audio Track { AudioCD drive = CDDriveChooser.drive; MServer.FS = drive.getTrack(file_to_play); mediainfo[0] = filename; mediainfo[1] = string.Empty; } else if (location_type == 4) //Tidal Track { Tidl tidl = TidalBrowser.tidl; url = await tidl.getStreamURL(Convert.ToInt32(file_to_play)); mediainfo = await tidl.getNameAndArtist(Convert.ToInt32(file_to_play)); } else if (location_type == 5) //Google Drive file (stream) { GDrive drive = GDriveForm.drive; url = await drive.GetUrl(file_to_play); mediainfo[0] = "Unknown"; mediainfo[1] = "Unknown"; } } else { nextMediainfo.CopyTo(mediainfo, 0); MServer.FS = NextTrack; trackLoaded = -1; } Thread.Sleep(100); if (location_type != 4 && location_type != 5) { url = "http://" + ip + ":" + port.ToString() + "/track" + Path.GetExtension(MServer.Filename); } SendFile(Device, item, url, mediainfo); } else { MessageBox.Show("Could not connect to device."); } } else { MessageBox.Show("No renderer selected"); } }
private async void LoadFile(int item = 0) { string file_to_play = MediaFileLocation[item]; int location_type = MediaFileLocationType[item]; string filename = MediaFiles.Items[item].ToString(); if (renderer != -1) { DLNA.DLNADevice Device = new DLNA.DLNADevice(DLNA.SSDP.Renderers[renderer]); if (Device.IsConnected()) { if (timer1.Enabled) { timer1.Stop(); } Device.StopPlay(); MServer.FS = new MemoryStream(); if ((filename.EndsWith(".opus") && decodeOpusToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".flac") && decodeFLACToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".mp3") && decodeMP3ToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".m4a") && decodeM4AToWAVToolStripMenuItem.Checked) || (filename.EndsWith(".wma") && decodeWMAToWAVToolStripMenuItem.Checked)) { MServer.Filename = Path.GetFileNameWithoutExtension(filename) + ".wav"; if (decodeToFLACInsteadOfWAVToolStripMenuItem.Checked) { MServer.Filename = Path.GetFileNameWithoutExtension(filename) + ".flac"; } } else { MServer.Filename = filename; } string url = null; if (item != trackLoaded) { TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Loading"; }); if (location_type == 1) //local file { mediainfo = await Extentions.getMetadata(file_to_play); int decodeMode = getDecodeMode(filename); if (decodeMode != 0) { TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Decoding"; }); MServer.FS = await Extentions.decodeAudio(file_to_play, decodeMode); } else { FileStream MediaFile = new FileStream(file_to_play, FileMode.Open, FileAccess.Read); await MediaFile.CopyToAsync(MServer.FS); MediaFile.Close(); } } else if (location_type == 2) //Google Drive file (local download) { GDrive drive = GDriveForm.drive; string tempFilename = Path.GetTempFileName(); TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Downloading"; }); await drive.DownloadFile(file_to_play, tempFilename); TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Downloaded"; }); int decodeMode = getDecodeMode(filename); mediainfo = await Extentions.getMetadata(tempFilename); if (decodeMode != 0) { TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Decoding"; }); MServer.FS = await Extentions.decodeAudio(tempFilename, decodeMode); } else { FileStream MediaFile = new FileStream(tempFilename, FileMode.Open, FileAccess.Read); await MediaFile.CopyToAsync(MServer.FS); MediaFile.Close(); } Extentions.deleteTempFile(tempFilename); } else if (location_type == 3) //CD Drive Audio Track { AudioCD drive = CDDriveChooser.drive; MServer.FS = drive.getTrack(file_to_play); mediainfo[0] = "Track " + (trackNum + 1).ToString(); mediainfo[1] = "Audio CD"; } else if (location_type == 4) //Tidal Track { Tidl tidl = TidalBrowser.tidl; url = await tidl.getStreamURL(Convert.ToInt32(file_to_play)); mediainfo = await tidl.getNameAndArtist(Convert.ToInt32(file_to_play)); } else if (location_type == 5) //Google Drive file (stream) { GDrive drive = GDriveForm.drive; try { url = await drive.GetUrl(file_to_play); mediainfo[0] = "Unknown"; mediainfo[1] = "Unknown"; } catch { MessageBox.Show("Cannot stream the file directly. Please change the Google Drive mode to \"download first\" and add them again to the queue."); } } TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Ready"; }); } else { nextMediainfo.CopyTo(mediainfo, 0); MServer.FS = NextTrack; } Thread.Sleep(100); if (location_type != 4 && location_type != 5) { url = "http://" + ip + ":" + port.ToString() + "/track" + Path.GetExtension(MServer.Filename); } if (status != 0) { SendFile(Device, item, url, mediainfo); } } else { MessageBox.Show("Could not connect to device."); } } else { MessageBox.Show("No renderer selected"); } }