Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

How to play an Mp3 audio file from URL in Unity

Posted on April 23, 2020April 23, 2020 by Habibie

I’m wondering how can I play an mp3 audio file from URL in Unity. So I tried to search around and I found the solution.

Watch this video below:

This is the script used in this project:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class testscript : MonoBehaviour
{
	
    AudioSource audioSource;
    AudioClip myClip;
    void Start()
    {
		audioSource = GetComponent<AudioSource>();
        StartCoroutine(GetAudioClip());
		Debug.Log("Starting to download the audio...");
    }

    IEnumerator GetAudioClip()
    {
        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("https://ciihuy.com/downloads/music.mp3", AudioType.MPEG))
        {
            yield return www.SendWebRequest();

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else
            {
                myClip = DownloadHandlerAudioClip.GetContent(www);
                audioSource.clip = myClip;
                audioSource.Play();
				Debug.Log("Audio is playing.");
            }
        }
    }
	
	
	public void pauseAudio(){
		audioSource.Pause();
	}
	
	public void playAudio(){
		audioSource.Play();
	}
	
	public void stopAudio(){
		audioSource.Stop();
	
	}
}

This Unity package can play an mp3 audio file stored on my web server. Download it here: https://drive.google.com/open?id=1u97pcEMQFPdqgVCx0nSm-J67367oOKHr

Please note that this thing won’t work on desktop platform, so please use it for Android or iOS platform, I’ve tested it.

Post Views: 869
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme