[Open Source] AudioImporter


Asset Store | Github

Here is a free package that lets you import mp3 files at runtime.

AudioImporter enables you to import audio files at runtime in Unity. It loads an audio file into an AudioClip. The package includes a simple file browser that can be used to select a file.

An optional importer using BASS dll and BASS net is included as a separate package. This importer needs additional licenses and steps to use. See Using Bass Importer for more information.

Features:

  • Asynchronous importing

  • File browser

  • Supports Windows, Android and iOS

5 Likes

A small update. This now includes an importer that uses Bass.dll and the importers are now derived from MonoBehaviour.

1 Like

Wow thankyou very much, this is going to help me a lot in a future project. Can’t believe nobody has given you a thanks in all this time.

1 Like

Thank you for sharing this for free! I don’t understand why didn’t you get more attention for such useful tool like that one.

1 Like

i think because there are quite a few free runtime file browser out there.

Is free this??

Yes. One of the importers uses Bass.dll, which is not free for commercial projects, but every importer is optional.

@HelloMeow this is supppperrr useful, so many thanks. I emailed u before, can’t wait for new update from RhythmTool, no memory allocations every frame plz :slight_smile:

Hello,

It seems very interesting but I still can’t do it Works…

I’m using Unity 5.3.3f1 on a Windows 8.1 to test it.

I have also downloaded the rythmtool sample: it opens, navigate for the folders but nothing sounds after select an mp3…

Any idea about what I’m doing wrong?

It seems easy to follow when I read but anyone has any step by step guide to be sure I have done everything correct?

Thanks!

Hey there. So I’ve been working on a game using your rhythm tool as well as these .mp3 importer.

I was coming up against an issue where some mp3 files would not be able to load. After a bit of messing around, I found that the while loop in FillBuffer() in the DecoderImporter class would get stuck.

Read would return 0, and therefore index would not increase. I am not 100% sure why the issue happens but a simple solution is to check if index + read is equal to index, and break out of the while loop if the condition is met.

Hopefully this can help anyone else that might be running into this issue

Thanks for reporting this issue, I’m going to look into it.

Version 3.0 is ready. I’ve decided to put it up on the Asset Store and Github to make it easier to add to a project. It should be available on the asset store soon.

Hi, I’m using the importer (and rhythm tool) to play audio clips from local storage (Android).
It loads and plays the first song fine, but the Loaded event is not triggered a second time.

loadSong (){
importer.Loaded += songLoaded;
importer.Import(getSelectedSong());
}

the second run gives this error:
07-09 14:01:25.680 7832 7846 E Unity : ArgumentNullException: Value cannot be null.
07-09 14:01:25.680 7832 7846 E Unity : Parameter name: _unity_self
07-09 14:01:25.680 7832 7846 E Unity : at (wrapper managed-to-native) UnityEngine.Networking.UnityWebRequest.Abort(UnityEngine.Networking.UnityWebRequest)
07-09 14:01:25.680 7832 7846 E Unity : at MobileImporter.Abort () [0x00008] in :0
07-09 14:01:25.680 7832 7846 E Unity : at AudioImporter.Import (System.String uri) [0x00000] in :0
07-09 14:01:25.680 7832 7846 E Unity : at SpawnScript.loadSong () [0x00047] in :0

My current workaround is to comment out the Abort() call in Import(string uri) (AudioImporter.cs:50)
This solves the issue, but I wonder if I’m doing something wrong… or it is a bug

I think I might have fixed this last month, but I haven’t updated the Asset Store package yet. Try this version on github:
https://github.com/Hello-Meow/AudioImporter/blob/master/Assets/AudioImporter/Scripts/MobileImporter.cs

By the way, in loadSong() you appear to subscribe to the AudioImporter.Loaded event every time. You’d only want to subscribe to this once. In Awake for example. Otherwise it will invoke songLoaded() an increasing number of times, every time you use loadSong().

Thanks, will check the update.

I was doing tests with the event subscription (deregistering in songLoaded(), or one time register at Start()), as I first thought the problem was related to the event handling (on second trigger). But thanks for commenting the potential issue :slight_smile:

Hello, excuse me, i want to use your asset in my work. But i have some troubles. On the first screenshot you can see the path to file i want to read (it is mp3 file).
On the second screenshot there is code.
On the third screenshot there is file i want to read. (Расположение = Path)
Could you help me out?4751693--451043--bandicam 2019-07-16 16-00-53-203.jpg

4751693--451055--bandicam 2019-07-16 16-05-36-258.jpg

Hi,

AudioImporter is a component. You can’t instantiate a new component like that. You have to use AddComponent or GetComponent.

That while loop will probably freeze the game. Progress will never reach 1 in the same frame unless there is an error opening the file.

Please see the included example.

Thank you for quick response.

I do all like in example. But there is no changes.
I try perform that script with AudioImporter and with NAudioImporter to. Anyway it writes: “is null”.4755272--451493--bandicam 2019-07-17 13-18-48-155.jpg
4755272--451481--bandicam 2019-07-17 13-18-24-063.jpg4755272--451487--bandicam 2019-07-17 13-18-01-608.jpg
4755272--451511--bandicam 2019-07-17 13-46-52-899.jpg

Hi, very clean interface for the importer. However, using mobile importer my whole game freezes on android (for about 1-2 seconds) while the import is happening. My code is straight from the example - with Coroutine and all that. Any advice? Thanks

I’ve noticed this as well and it appears to be caused by
DownloadHandlerAudioClip.GetContent. It’s a bug according to this thread .