Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Apr 03, 2015 at 08:34 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ackley14 · Mar 06, 2015 at 04:47 PM · editorbuildaudioogg

[closed]Music works in editor but not in build?

Hiya. I've been working on a simple audio player for learning purposes and I've hit a snag. Everything works PERFECTLY....until I build it. In the editor its flawless but when I build it, essentially nothing happens. everything, gui, song list, ect, loads fine. but the music wont start. upon further investigation, I found that "audio.isReadyToPlay" was returning false in the build version but true in the editor. Im completely stumped as to why as everything I've looked at says it should be working just fine! Heres the main script. There are two to this package but theres no need for the other one as its simply a controller and does not effect the actual playing of music.

 import System.IO;
 import System.Collections.Generic;
  var temp = 0.0;
  var timeout = 0.0;
  //var playy = true;
  var wwwar :List.<AudioClip>;
  var fileinfo : Array;
  var fil: int;
  var cursong: int;
  var ffwd : GUIStyle;
  var rwd: GUIStyle;
  var refresh:GUIStyle;
  var stop:GUIStyle;
  var pause : GUIStyle;
 var play : GUIStyle;
  var original: List.<String>;
  var ischanged: boolean;
  var originalWidth = 1280.0; // define here the original resolution
 var originalHeight = 720.0; // you used to create the GUI contents
 private var scale: Vector3;
  var ScrollVector : Vector2 = Vector2.zero;
  PlayerPrefs.DeleteAll();
      function Start() {
      
         //var dataloc : String = Application.dataPath.Substring(0,Application.dataPath.length - " Asset".length);
         //var www = new WWW("File://Fearofdark - Motorway - 02 Suburban Supernatural.ogg");
     //print(Application.dataPath.Substring(0,Application.dataPath.length - " Asset".length));
         //wwwarray.clear();
         try{
         fileinfo = DirectoryInfo(Application.dataPath + "//..//music//").GetFiles("*.ogg");
         print("success");
         }catch(e:Exception){
         print(e);
         print("failure");
         Directory.CreateDirectory((Application.dataPath + "//..//music//"));
         fileinfo = DirectoryInfo(Application.dataPath + "//..//music//").GetFiles("*.ogg");
         }
         
         for(i = 0 ; i < fileinfo.length ; i++){
         var tempwww = WWW("File://"+fileinfo[i]);
          wwwar.Add(tempwww.audioClip);
          print("added file: " + tempwww);
         }
         audio.clip = wwwar[0];
         print("added song to audio.clip");
         cursong = 0;
         fil = fileinfo.length;
     }
     function LoadMusicList(){
     wwwar.Clear();
     temp = 0.0;
     audio.timeSamples = temp;
     Start();
     musicload(0);
     }
 
     function OnGUI () {
     scale.x = Screen.width/originalWidth; // calculate hor scale
 scale.y = Screen.height/originalHeight; // calculate vert scale
 scale.z = 1;
 var svMat = GUI.matrix; // save current matrix
 // substitute matrix - only scale is altered from standard
 GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
 // draw your GUI controls here:
     
     if (!audio.isPlaying){
         if(GUI.Button(Rect(800,50,50,50),"",play)){
             PMusic();
             }
         }else{
         if(GUI.Button(Rect(800,50,50,50),"",pause)){
             PMusic();
             }
         }
             
             
             
     temp = audio.timeSamples;        
      try{
      temp = (GUI.HorizontalSlider(Rect(45,78+(cursong*60),250,20),temp,0,audio.clip.samples));
      }catch(e:Exception){
      print(e);
      temp = (GUI.HorizontalSlider(Rect(45,78+(cursong*60),250,20),temp,0,1));
      }
      audio.timeSamples = temp;
      GUI.Label(Rect(45,62+(cursong*60),100,100), stt(audio.time));
      if (GUI.Button(Rect(745,50,50,50),"",rwd)){ playprev();}
      if (GUI.Button(Rect(855,50,50,50),"",ffwd)){ playnext();}
      if (GUI.Button(Rect(910,50,50,50),"",refresh)){ LoadMusicList();}
      if (GUI.Button(Rect(965,50,50,50),"",stop)){ stopsong();;}
      //print(DirectoryInfo(Application.dataPath + "//..//music//"));
      
      // end your GUI controls here:
 GUI.matrix = svMat; //restore matrix
      }
 
      
     function musicload(t){
     timeout = 0.0;
     
     try{audio.clip = wwwar[t];}catch(e:Exception){LoadMusicList();audio.clip = wwwar[t];print(e);}
     while(!audio.isPlaying && timeout < 10){
     yield WaitForSeconds(0.5);
     timeout = timeout + 0.5;
     PMusic();
     }
     timeout = 10;
     temp = 0;
     audio.timeSamples = temp;
     cursong = t;
     }
     function PMusic(){
     if(!audio.isPlaying && audio.clip.isReadyToPlay){
     print("test");
         audio.Play();
     }else{
     print("test2");
     print(audio.isPlaying);
     print(audio.clip.isReadyToPlay);
         audio.Pause();
     }
     }
     function stt(sec){
      if (float.IsNaN(sec) || sec == Mathf.Infinity){sec = 0.0;}
      var hours = Math.Floor(sec/3600).ToString("00");
      var minutes = Math.Floor(sec / 60).ToString("00");
      var seconds = (sec % 60).ToString("00");
      
      return (hours + ":" + minutes + ":" + seconds);
     }
     function playnext(){
     if(cursong == fil-1){
     musicload(0);
     }else{
     musicload(cursong+1);
     }
     }
     
     
     function playprev(){
     if(cursong == 0){
     musicload(fil-1);
     }else{
     musicload(cursong-1);
     }
     }
     
     function stopsong(){
     audio.Stop();
     temp = 0.0;
     audio.timeSamples = temp;
     
     
     }
     
     
     
     

I know its sloppy, I don't care. I know I didn't do everything in the most perfect of ways, again, I don't care. I'm still new to this whole thing so I hope you understand. Also, I can't use resources.load as I need to be able to import them raw on load. TYVM for any help offered!

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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by ackley14 · Apr 03, 2015 at 03:30 PM

Turns out unity uses slightly different wording between the editor file system, and the build filesystem :

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

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

video-audio not playing in build (i tried webgl and android) 0 Answers

SoundFX - ogg or native wav? 1 Answer

Cancel build in PostProcessScene? 0 Answers

c# ai script works in editor but not in build 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