Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Audio Playlist

Discussion in 'Scripting' started by MrBodean, Apr 30, 2008.

  1. MrBodean

    MrBodean

    Joined:
    Jan 25, 2008
    Posts:
    103
    Hey ya'll,
    I am trying to load a audio playlist that plays one song after the other and call them from the web with www. It calls a php file which returns a random song in its list.

    All is working EXCEPT figuring out how long to Wait before loading the next song. I tried audio.clip.length but that does not seem to be working. I can put a wait of say 10 secs, and it does what it is suppose to do, but of course does not play the entire song.

    Attached is the script I am playing with. Any help is much appreciated...

    ==================

    var url : String="http://www.friendshangout.com/unity/audio/playlist01.php";


    function Start ()
    {

    LoadAudio();
    }


    function PlayAudio()
    {
    audio.Play();
    yield new WaitForSeconds (10);
    // yield WaitForSeconds(audio.clip.length);
    LoadAudio();
    }

    function LoadAudio()
    {
    www=new WWW(url);
    audio.clip=www.audioClip;
    }


    function Update ()
    {
    if(!audio.isPlaying audio.clip.isReadyToPlay)

    PlayAudio();
    }


    @script RequireComponent(AudioSource)