• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by jack_rabbit · Jun 21, 2012 at 12:17 PM · androidaudioruntimeimportingmp3

Loading Audio Files at Runtime for Playback and Processing

Hi,

I am currently trying to implement something where (on Android, iOS & PC) mp3s are loaded at runtime and played back to the user. I also need to be able to access the raw PCM data to do some processing on it.

Using the WWW class is no option, because that eats memory like no other. (Even if that weren't a problem, due to a bug in the getData method of AudioClip I can not access the raw data, once I've created an AudioClip from a file loaded through the WWW class. And then it also won't read mp3s on some platforms)

I have tried various libraries and so far only paid ones worked (fmod, etc), but these are not an option for me. (I need an open source solution)

Currently trying to get ffmpeg to work, but none of the C# wrappers I have found seem to be any good. The neat thing about it is that it uses streams though, which greatly reduces memory usage especially when handling PCM data. ....If I could just get it to work.

Does anyone have any experience in that regard? Help with either ffmpeg or another approach would be greatly appreciated! :)

Thanks!

Comment
Tim-Michels
Nelien
murkantilism
gregroberts

People who like this

4 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nelien · Jun 22, 2012 at 04:28 PM 0
Share

Any update on this? Would like to know this as well.

1 Reply

  • Sort: 
avatar image

Answer by jack_rabbit · Aug 22, 2012 at 10:54 AM

Update: Getting to the end of the project and thought I'd let everyone know how we worked around it.

As stated before, loading the entire song into unity through WWW eats memory. It allocates roughly 2x-3x the songs full PCM size (which for a 3 minute mp3 means about 2x-3x 60MB!).

So what we did was to compile mpg123 for ARMv7, find a C# wrapper for it and decode the mp3's "by hand". This was a bit of a hassle to get working, but it works and does so quick(ish). Because we use plugins this means that only pro/mobile users can do this though.

This approach limits us to solely mp3s (and WAVs), but due to licensing we wouldn't be able to afford to decode m4a/aac anyway.

Comment
murkantilism

People who like this

1 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image concave · Mar 02, 2014 at 08:59 PM 0
Share

dear jack rabbit! i'am searching for a solution to playback mp3 from filesystem. i still don't now why but the www class doesn't support the playback on iOS from filesytem "file://". i was researching on a solution using mpg123 but if i think of a commerical game - isn't mpg123 gpl? and isn't the mp3 license expensive aswell? can you help me with some background information? kind regards.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Import .mp3 and use it as AudioClip 1 Answer

can't load music (wav and mp3 ) on android but the code works fine in editor and window build 0 Answers

Android play mp3 file 0 Answers

Best Audio File Format Practices? iOS/Unity 1 Answer

Playing mp3 files on Android 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges