Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by hermes · Aug 18, 2013 at 03:33 AM · wwwmp3mp4

How to play mp3, mp4 files on the local disk

I use the www, but it only supports ogg format, How to play mp3, mp4 files on the local disk

Comment
Add comment · 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 Kagedmonkey40 · Mar 28, 2016 at 12:41 AM 0
Share

O$$anonymous$$, this is driving me nuts! I have been trying for days to get a unity game to load a .ogg or .mp3 file from the strea$$anonymous$$g assets folder using WWW. It works great on the standalone PC build and while in the editor. However on android I just get the error message "strea$$anonymous$$g ".ogg" not supported on this platform". I've been searching for days now and this seems like it should be a straightforward thing to do- load an external audio file...how common and mundane of a task to be so damned difficult (if not impossible).

Why in the name of all that is holy does Unity not document how to do this task, which seems many people are struggling with?

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by save · Aug 19, 2013 at 10:28 AM

The short answer is, you cannot play certain media files with Unity without a proper plugin. You need a license.

You can however play ogg- and wav-files, as a small bandaid to this void of an answer, importing them at runtime could look like this:

 #pragma strict
 
 import System.Collections.Generic;
 import System.IO;
 
 static var path : String = "./"; // Is equal to where you have your executable
 static var fileTypes : String[] = ["ogg", "wav"]; // Valid file types
 
 static var files : FileInfo[];
 static var audioSource : AudioSource;
 static var audioClips : List.<AudioClip> = new List.<AudioClip>();
 
 function Start () {
     // If in editor the path is in Assets folder
     if (Application.isEditor)
         path = "Assets/";
     
     // Set an AudioSource to this object
     audioSource = audio;
     if(audioSource == null)
         audioSource = gameObject.AddComponent(AudioSource);
     
     // Find files in directory        
     yield GetFilesInDirectory();
     
     // Play a clip found in directory
     if (audioClips.Count>0) {
         audioSource.clip = audioClips[0];
         audioSource.Play();
     }
 }
 
 function GetFilesInDirectory () {
     var info : DirectoryInfo = new DirectoryInfo(path);
     files = info.GetFiles();
     for (var file : FileInfo in files) {
         var extension : String = Path.GetExtension(file.FullName);
         if (ValidType(extension))
             yield LoadFile(file.FullName);
     }
 }
 
 function ValidType (extension : String) : boolean {
     for (var validExtension : String in fileTypes)
         if (extension.IndexOf(validExtension) > -1)
             return true;
     return false;
 }
 
 function LoadFile (path : String) {
     var www : WWW = new WWW("file://"+path);
     var clip : AudioClip = www.audioClip;
     while (!clip.isReadyToPlay)
         yield;
     clip = www.GetAudioClip(false);
     var parts : String[] = path.Split("\\"[0]);
     clip.name = parts[parts.Length-1];
     audioClips.Add(clip);
 }


Comment
Add comment · 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 Sajidfarooq · Aug 19, 2013 at 10:35 AM 0
Share

Comprehensive answer. Up-voted.

avatar image
2

Answer by Warped · Mar 19, 2015 at 10:57 PM

Here is one way to use library for playing link text

Comment
Add comment · 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
-3

Answer by Benproductions1 · Aug 19, 2013 at 08:20 AM

http://lmgtfy.com?q=Unity+Play+Audio+from+File

Comment
Add comment · Show 4 · 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 Sajidfarooq · Aug 19, 2013 at 09:00 AM 3
Share

@Benproductions1, you missed his point. the OP doesnt want to play files already imported into Unity. He wants to play "external" files. The primary way to do that is using WWW, but remember that plays Ogg files only, not $$anonymous$$P3. Hence, his question.

Its actually a legitimate question. For reference, see this related question.

avatar image Benproductions1 · Aug 19, 2013 at 11:47 AM 0
Share

I did not miss the point. The whole point was to show that currently there is no way of doing what he wants, as seen in one of the search results.

The point of my answer was to show that his question had already been answered before, specifically the "related question" you linked to, which answeres the question here.

If the OP would have simply done a google search he would not have had to post the question :)

avatar image Sajidfarooq · Aug 19, 2013 at 02:57 PM 3
Share

Ben, its always easier to find out if something works, rather than if it doesn't work. Why? Because if something works, you find the solution via Google. If it doesnt, you will find many people saying it can't be done, but you can't get the feeling out of your $$anonymous$$d that perhaps there is someone out there who "can" get it done.

So my logic is simply this: If its already answered, and if it can be done, point to the relevant answer. If it "can't" be done, then repeat the answer again + point to older answer.

avatar image ganesh · Sep 30, 2014 at 03:52 AM 0
Share

Is this useful for android

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Streaming MP3s in WebGL Editor 0 Answers

Load mp3 from Harddrive on PC (again) 1 Answer

WWW.getAudioClip() returning wrong length from one server but not another 0 Answers

WWW load mp3 GetAudioClip without stream,play only a part,then no sound. 0 Answers

What video formats can I use loading from the streaming assets folder? 2 Answers


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