Example #1
0
        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");
            }
        }
Example #2
0
        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");
            }
        }
Example #3
0
        private async void LoadNextTrack(int item)
        {
            string file_to_play  = MediaFileLocation[item];
            int    location_type = MediaFileLocationType[item];
            string filename      = MediaFiles.Items[item].ToString();

            trackLoading = true;
            {
                try
                {
                    NextTrack = new MemoryStream();
                    if (location_type == 1) //local file
                    {
                        nextMediainfo = 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"; });
                            NextTrack = 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(NextTrack);

                            MediaFile.Close();
                        }
                    }
                    else if (location_type == 2) //Google Drive file
                    {
                        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"; });
                        nextMediainfo = await Extentions.getMetadata("tempfile");

                        int decodeMode = 0;
                        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"; });
                            NextTrack = 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;
                        NextTrack        = drive.getTrack(file_to_play);
                        nextMediainfo[0] = filename;
                        mediainfo[1]     = string.Empty;
                    }
                    trackLoaded  = item;
                    trackLoading = false;
                }
                catch { trackLoading = false; }
            }
        }
Example #4
0
        private async void LoadNextTrack(int item)
        {
            string file_to_play  = MediaFileLocation[item];
            int    location_type = MediaFileLocationType[item];
            string filename      = MediaFiles.Items[item].ToString();

            trackLoading = true;
            {
                try
                {
                    TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Loading"; });
                    NextTrack = new MemoryStream();
                    if (location_type == 1) //local file
                    {
                        nextMediainfo = await Extentions.getMetadata(file_to_play);

                        int decodeMode = getDecodeMode(filename);
                        if (decodeMode != 0)
                        {
                            TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Decoding"; });
                            NextTrack = await Extentions.decodeAudio(file_to_play, decodeMode);
                        }
                        else
                        {
                            FileStream MediaFile = new FileStream(file_to_play, FileMode.Open, FileAccess.Read);
                            await MediaFile.CopyToAsync(NextTrack);

                            MediaFile.Close();
                        }
                    }
                    else if (location_type == 2) //Google Drive file
                    {
                        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"; });
                        nextMediainfo = await Extentions.getMetadata(tempFilename);

                        int decodeMode = getDecodeMode(filename);
                        if (decodeMode != 0)
                        {
                            TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Decoding"; });
                            NextTrack = await Extentions.decodeAudio(tempFilename, decodeMode);
                        }
                        else
                        {
                            FileStream MediaFile = new FileStream(tempFilename, FileMode.Open, FileAccess.Read);
                            await MediaFile.CopyToAsync(NextTrack);

                            MediaFile.Close();
                        }
                        Extentions.deleteTempFile(tempFilename);
                    }
                    else if (location_type == 3) //CD Drive Audio Track
                    {
                        AudioCD drive = CDDriveChooser.drive;
                        NextTrack        = drive.getTrack(file_to_play);
                        nextMediainfo[0] = "Track " + (item + 1).ToString();
                        nextMediainfo[1] = "Audio CD";
                        mediainfo[1]     = string.Empty;
                    }
                    trackLoaded  = item;
                    trackLoading = false;
                    TrackPositionLabel.Invoke((MethodInvoker) delegate { TrackPositionLabel.Text = "Ready"; });
                }
                catch { trackLoading = false; }
            }
        }