DirectX does exist in the namespace "Microsoft"...

Hi! I intended to use directx to play some .mp3 files outside of compiled game. Like this:

using UnityEngine;
using System.Collections;
using Microsoft.DirectX.AudioVideoPlayback;

public class LegendasVozes : MonoBehaviour
{

	Audio Teste = new Audio("Arquivo/Vozes/0001.mp3");

        void Start ()
	{
                Teste.play();
        }
}

But this error appear on the unity console:

Assets/LegendasVozes.cs(5,17): error CS0234: The type or namespace name `DirectX' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?

Please, help!

Unity already has support for .mp3 files… use the WWW function or file I/O.

Ok! Thanks for the tip… But now i have a problem with this method:

WWW class are used to access WorldWideWeb files, right? If case, this don’t need this…

This “file I/O” you mean the System.IO? How can i use this?

Thanks…

Use file:// instead of http://

–Eric

That is really useful Eric, thanks…

But I could not make it work ¬¬

AudioClip Voz = new AudioClip();

WWW teste = new WWW("file://C:/Users/Vinícius/Documents/GUI's Test/Arquivos/Vozes/0001.mp3");

Voz = teste.audioClip;

audio.clip = Voz;
audio.Play();

Nothing happens, not even an error!

PS: I already test using a .ogg file instead of .mp3 and using this path:

WWW teste = new WWW("file://Arquivos/Vozes/0001.mp3");

What i need to do to this works!? :face_with_spiral_eyes:

Unfortunately callahan.44 is mistaken; there is no support for MP3 (unless you’re using iOS or possibly Android). You’d use WWW.oggVorbis.

–Eric

“Grande Eric”! PS: It is a great greeting in Portuguese of Brazil. XD

Mate, I have tried this:

WWW teste = new WWW("file://C:/Users/Vinícius/Documents/GUI's Test/Arquivos/Vozes/0001.ogg");

Voz = teste.oggVorbis;

audio.clip = Voz;
audio.Play();

But this error appear:

begin<end
UnityEngine.WWW:get_oggVorbis()
LegendasVozes:Legenda(Int32) (at Assets/LegendasVozes.cs:45)    // the .oggVorbis line
LegendasVozes:Start() (at Assets/LegendasVozes.cs:64)           // It is the call of the method where all this should all works.

Another tip, please!?

Maybe there’s something wrong with your .ogg file?

–Eric

I figured out what was wrong!

The Path have accentuation, be cause the name of my Windows User.

Thanks Eric, I spent some time trying to make it work.

The last thing what I need is guide the path to the same folder that the game will be/ the script will be…

Something like this:

string Path = "Arquivos/Vozes/0001.ogg";

PS: The “Arquivos/” folder will stay inside the same folder as the .exe of the compiled game.

It is programmable in unity? :face_with_spiral_eyes:

You should use Application.dataPath.

–Eric

Oh, God! Everything working just the way I had planned…

Thanks for everything and sorry for any inconvenience.

doh my bad

WWW.audioClip
Description
Returns a AudioClip generated from the downloaded data (Read Only).
The data must be an audio clip in Ogg Vorbis format.

Sucks a bit, I was hoping to play peoples MP3 collections rather than include music. lol

Well, in my case everything except for a few tracks is lossless or AAC, so that wouldn’t always work anyway.

–Eric