Ejemplo n.º 1
0
 /// <summary>
 /// Stops the music currently being played and suspends the playlist if any
 /// </summary>
 public void StopSong(float fadeTime = 0.0f)
 {
     if ((this.currentSongName != null) && (this.currentSongName != string.Empty))
     {
         pendingMusic = "";
         if (fadeTime > 0.0f)
         {
             this.fadeTime     = fadeTime;
             this.fadeTimeLeft = fadeTime;
             this.fadingOut    = true;
             this.stopMusic    = true;
         }
         else
         {
             //stop and clear
             this.songSource.Stop();
             this.songSource.clip = null;
             //this.songSource = null;
             this.currentSongName    = null;
             this.currentPlaylistDef = null;
             this.currentPlaylist    = null;
             this.currentSongRepeat  = false;
         }
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Set a playlist as the current one
    /// </summary>
    private void setNewPlaylist(AudioCatalog.PlaylistDef playlist)
    {
        currentPlaylistDef = playlist;
        currentPlaylist    = playlist.Songs.Clone() as string[];

        //make sure index are in range
        if (this.currentPlaylistDef.Index >= currentPlaylist.Length)
        {
            this.currentPlaylistDef.Index = 0;
        }
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Searchs for a Playlist in all the catalogs currently in memory
 /// </summary>
 private AudioCatalog.PlaylistDef findPlaylistInCatalogs(string Id)
 {
     AudioCatalog.PlaylistDef retVal = null;
     for (int i = 0; i < this.audioCatalogs.Length; i++)
     {
         AudioCatalog.PlaylistDef c = this.audioCatalogs[i].GetPlaylist(Id);
         if (c != null)
         {
             retVal = c; break;
         }
     }
     return(retVal);
 }
Ejemplo n.º 4
0
    private void doPlayMusic(string Id, bool loop, bool inmediate = false)
    {
        AudioCatalog.PlaylistDef playlist = this.findPlaylistInCatalogs(Id);
        if (playlist != null)
        {
            if (currentPlaylistDef != playlist)
            {
                setNewPlaylist(playlist);
                playlistPlayNext();
            }
        }
        else
        {
            //clear current playlist
            currentPlaylistDef = null;
            currentPlaylist    = null;

            //try to play the Id as a song
            this.playSong(Id, loop, inmediate);
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Plays the next in the playlist, and points to the next one
    /// </summary>
    private void playlistPlayNext()
    {
        //make sure index are in range
        if (this.currentPlaylistDef.Index >= currentPlaylist.Length)
        {
            this.currentPlaylistDef.Index = 0;
        }
        string nextSong = currentPlaylist[currentPlaylistDef.Index];

        if (nextSong != currentSongName)
        {
            bool played = false;

            //make sure it's available
            if (findSongInCatalogs(nextSong) != null)
            {
                playSong(nextSong, false);
                //increment the index of the playlist
                this.currentPlaylistDef.Index++;
                played = true;
            }
            else
            {
                AudioCatalog.PlaylistDef playlist = findPlaylistInCatalogs(nextSong);
                if (playlist != null)
                {
                    setNewPlaylist(playlist);
                    played = true;
                }
            }

            if (!played)
            {
                Debug.LogError(
                    string.Format("Song {0} of Playlist {1} not found!", nextSong, currentPlaylistDef.Id));
            }
        }
    }