Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,882 questions

51,808 answers

573 users

How to download mp3 from URL in C#

1 Answer

0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        async Task DownloadMP3(string url, string path)
        {
            using (var httpclient = new HttpClient())
            {
                using (var stream = await httpclient.GetStreamAsync(url))
                {
                    using (var fileStream = File.Create(path))
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                }
            }
        }
        public Form1()
        {
            InitializeComponent();
        }

        async private void button1_Click(object sender, EventArgs e)
        {
            string url = "https://download.samplelib.com/mp3/sample-6s.mp3"; 

            string path = "song.mp3"; // path = c:\Users\A\source\WinFormsApp1\WinFormsApp1\bin\Debug\net7.0-windows\WinFormsApp1.exe

            await DownloadMP3(url, path);

            label1.Text = "MP3 file downloaded successfully";
        }
    }
}



/*
 * run:
 *
 *
 */


 



answered Jul 29, 2023 by avibootz
edited Aug 18, 2023 by avibootz

Related questions

3 answers 228 views
228 views asked Sep 21, 2019 by avibootz
1 answer 223 views
2 answers 132 views
1 answer 230 views
1 answer 188 views
188 views asked Mar 10, 2017 by avibootz
1 answer 146 views
146 views asked Mar 10, 2017 by avibootz
...