Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Music player - get songs from directory.

$
0
0
Hi guys, i've made this music player, the songs are added from unity editor, how can i do for create a directory folder, so that the songs that must be reproduced are taken from there? #pragma strict var CurrentSong : AudioClip = null; var SongList : AudioClip[]; var gSkin : GUISkin; var SongName : String; var Music : AudioSource; //per usare lo stex input! var on : boolean; var SongNumber : int = 10; var showGUI : boolean = false; //Volume Audio var hSliderValue : float = 0.0; function Start(){ CurrentSong = SongList[SongNumber]; Music = gameObject.GetComponent(AudioSource); Music.loop = false; Music.playOnAwake = false; Music.clip = CurrentSong; Music.volume = 2; audio.Play(); NextSong(); } function Update () { //Volume Audio audio.volume = hSliderValue; SongName = CurrentSong.name; Music = gameObject.GetComponent(AudioSource); Music.clip = CurrentSong; if (SongNumber > SongList.length - 1) { SongNumber = 0; } if (SongNumber < 0) { SongNumber = SongList.length - 1; } } function OnMouseDown () { if (Input.GetMouseButton){ //Per usare lo stex Input! on= !on; if (!on) { showGUI = true; } if (on) { showGUI = false; } } } function OnGUI(){ if(showGUI){ GUI.skin = gSkin; GUI.Box(Rect(10, Screen.height-125, 420, 130), SongName); //Volume Audio hSliderValue = GUI.HorizontalSlider (Rect (180, Screen.height-28, 180, 100), hSliderValue, 0.0, 1.0); if(GUI.Button(Rect(30, Screen.height-41, 40, 40), "<<")){ SongNumber -= 1; CurrentSong = SongList[SongNumber]; Wait(); } if(audio.isPlaying){ if(GUI.Button(Rect(75, Screen.height-41, 40, 40), "||")){ audio.Pause(); } } if(!audio.isPlaying){ if(GUI.Button(Rect(75, Screen.height-41, 40, 40), ">")){ audio.Play(); } } if(GUI.Button(Rect(120, Screen.height-41, 40, 40), ">>")){ SongNumber += 1; CurrentSong = SongList[SongNumber]; Wait(); } } } function Wait(){ yield WaitForSeconds(0.05); audio.Play(); } function NextSong(){ yield WaitForSeconds (audio.clip.length); SongNumber += 1; CurrentSong = SongList[SongNumber]; Wait(); }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>