Version: Unity 6.1 (6000.1)
LanguageEnglish
  • C#

AudioType

enumeration

Suggest a change

Success!

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.

Close

Submission failed

For 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.

Close

Cancel

Description

The 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(); } } } }

Properties

Property Description
UNKNOWNThe audio file you want to stream has a file format that is unknown to Unity.
ACCThe audio file you want to stream has the Advanced Audio Coding (AAC) digital audio file format. Unity doesn’t natively support this format.
AIFFThe audio file you want to stream has the Audio Interchange File Format (AIFF) audio file format. Unity doesn’t support this format.
ITThe audio file you want to stream has the Impulse Tracker (IT) audio file format.
MODThe audio file you want to stream has the Protracker / Fasttracker MOD audio file format.
MPEGThe audio file you want to stream has the MPEG (MP2 or MP3) audio file format.
OGGVORBISThe audio file you want to stream has the Ogg Vorbis audio file format.
S3MThe audio file you want to stream has the ScreamTracker 3 audio file format.
WAVThe audio file you want to stream has the Microsoft WAV audio file format.
XMThe audio file you want to stream has the FastTracker 2 XM audio file format.
XMAThe audio file you want to stream has the Xbox360 XMA audio file format.
VAGThe audio file you want to stream has the VAG audio file format for PlayStation.
AUDIOQUEUEThe audio file you want to stream uses Apple’s Audio Queue file format.