enumeration
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseThe format type of the imported (native) data.
Use this enumeration to specify the format type of the audio file you want to play. This is mostly useful if you stream your audio from a server with UnityWebRequestMultimedia.GetAudioClip. For example, if you want to stream a file with the .ogg file extension, use AudioType.OGGVORBIS.
UnityWebRequestMultimedia.GetAudioClip(www.example.com/your-file.ogg, AudioType.OGGVORBIS));
.
If you use the wrong format, the audio might not play correctly and Unity might throw an error.
Additional resources: UnityWebRequestMultimedia, DownloadHandlerAudioClip.GetContent.
// This script streams an MP3 audio file from the web. // First you have to change the url to a valid link to an MP3 audio file. // Attach this script to a GameObject.
using UnityEngine; using UnityEngine.Networking; using System.Collections;
public class MyBehaviour : MonoBehaviour { public AudioType audioType; AudioSource audioSource;
void Start() { // Add an AudioSource to your GameObject. audioSource = gameObject.AddComponent<AudioSource>(); StartCoroutine(GetAudioClip()); }
IEnumerator GetAudioClip() { // Replace the string with where you host your audio file. string url = "https://www.example.com/mp3sound.mp3";
// Stream audio, store it as an audio clip and play it. Make sure the file has an MPEG audio format. using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG)) { yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError) { Debug.Log(www.error); } else { AudioClip myClip = DownloadHandlerAudioClip.GetContent(www); audioSource.clip = myClip; audioSource.Play(); } } } }
UNKNOWN | The audio file you want to stream has a file format that is unknown to Unity. |
ACC | The audio file you want to stream has the Advanced Audio Coding (AAC) digital audio file format. Unity doesn’t natively support this format. |
AIFF | The audio file you want to stream has the Audio Interchange File Format (AIFF) audio file format. Unity doesn’t support this format. |
IT | The audio file you want to stream has the Impulse Tracker (IT) audio file format. |
MOD | The audio file you want to stream has the Protracker / Fasttracker MOD audio file format. |
MPEG | The audio file you want to stream has the MPEG (MP2 or MP3) audio file format. |
OGGVORBIS | The audio file you want to stream has the Ogg Vorbis audio file format. |
S3M | The audio file you want to stream has the ScreamTracker 3 audio file format. |
WAV | The audio file you want to stream has the Microsoft WAV audio file format. |
XM | The audio file you want to stream has the FastTracker 2 XM audio file format. |
VAG | The audio file you want to stream has the VAG audio file format for PlayStation. |
AUDIOQUEUE | The audio file you want to stream uses Apple’s Audio Queue file format. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.