chunik
New Member
Posts: 17
Posts: 17
|
Post by chunik on Sept 21, 2022 8:43:55 GMT
Hi,
i'm a bit confused with playlist controller api.
except i want to add a slider for currently playing song where you can click slider and move to a time of the song.. (like youtube time slider etc).
Also each song has paired scriptable object meta data, with composer and attribution if i have one with link to their page etc.
- i can handle the logic of playing songs on my own, but i can't find the list of imported songs, and i can't tell playlist to play a concrete song, only next song?
- so how would you implement something like this. Assume there is like data set (list) of all the songs, then there is player profile data set of the songs he has available/muted, that he can edit at run time. And i basically want to feed the data set to playlist, or just let the playlist tell me when the song is ending so my own script will tell it next song to play.
-also how to tell it to play song from specific time at run time (controller by the slider thing).
Cheers.
|
|
DarkTonic Dev
Administrator
Posts: 4,386
Posts: 4,386
Member is Online
|
Post by DarkTonic Dev on Sept 21, 2022 14:50:06 GMT
Are you aware there's a Song Metadata feature built in? You may not have had to write your own Scriptable Object.
The list of songs does exist, you can access it with:
var songName = PlaylistController.InstanceByName("YourPlaylistControllerName").CurrentPlaylist.MusicSettings[0].Alias;
I would advise to assign an alias to all songs because otherwise you need to use various properties to get to the "name" dependong on Audio Origin.
You can play a song by name with:
PlaylistController.InstanceByName("YourPlaylistControllerName").TriggerPlaylistClip("AliasOrSongName");
You cannot play a song from a specific time, you would need to play the song, and immediately tell it to jump to the time you want.
PlaylistController.InstanceByName("YourPlaylistControllerName").TriggerPlaylistClip("AliasOrSongName"); PlaylistController.InstanceByName("YourPlaylistControllerName").ActiveAudioSource.time = 3f;
Although I'm not sure what you mean by "imported songs". Are you hoping to have the user construct their playlist during play? That's not really supported.
I hope that helps.
|
|
chunik
New Member
Posts: 17
Posts: 17
|
Post by chunik on Sept 21, 2022 14:57:09 GMT
Great, Big Thanks. That looks like all i need i just pair the songs with my internal data some way. Couldn't find that path in intelisense.
|
|
DarkTonic Dev
Administrator
Posts: 4,386
Posts: 4,386
Member is Online
|
Post by DarkTonic Dev on Sept 21, 2022 19:22:42 GMT
No problem.
|
|
chunik
New Member
Posts: 17
Posts: 17
|
Post by chunik on Sept 26, 2022 9:20:07 GMT
I've got it working pretty much. One issue is that event song ended or playlist ended doesn't seem to fire. I have only one playlist in the scene.
myPlaylistController = PlaylistController.InstanceByName("PlaylistController"); myPlaylist = myPlaylistController.CurrentPlaylist; // cashing my references
var name = songSo.audioClip.name; myPlaylistController.TriggerPlaylistClip(name); //this is how i tell it to play the song, works fine
myPlaylistController.SongEnded += SongEnded; myPlaylistController.PlaylistEnded += PlaylistEnded;
//this two don't trigger when song ends, is it because i tell it to play just one song. In worst case i can manually track song time, or if song is playing etc, but maybe there is a better way.
|
|
DarkTonic Dev
Administrator
Posts: 4,386
Posts: 4,386
Member is Online
|
Post by DarkTonic Dev on Sept 26, 2022 18:28:09 GMT
I've been testing this. I can't get SongEnded to not fire, but PlaylistEnded may have an issue. I'll update here when I figure it out.
|
|
DarkTonic Dev
Administrator
Posts: 4,386
Posts: 4,386
Member is Online
|
Post by DarkTonic Dev on Sept 26, 2022 19:14:14 GMT
On line 672 in PlaylistController.cs, change the code to the following to make PlaylistEnded event work:
if (hasNoNextSong) { // 8/21/2017, the last song would not unload because it was never detected. FirePlaylistEndedEventIfAny(); CeaseAudioSource(_activeAudio); // this will release the resources if (PlaylistEnded != null) { PlaylistEnded(); } return; }
Like I said, I can't reproduce SongEnded not working. You will need to send me an example Scene that reproduces that not working.
-Brian
|
|
chunik
New Member
Posts: 17
Posts: 17
|
Post by chunik on Sept 27, 2022 2:26:04 GMT
On line 672 in PlaylistController.cs, change the code to the following to make PlaylistEnded event work:
if (hasNoNextSong) { // 8/21/2017, the last song would not unload because it was never detected. FirePlaylistEndedEventIfAny(); CeaseAudioSource(_activeAudio); // this will release the resources if (PlaylistEnded != null) { PlaylistEnded(); } return; }
Like I said, I can't reproduce SongEnded not working. You will need to send me an example Scene that reproduces that not working. -Brian Sending a project is too much work it has too many references to my other code, which would bring even more references in a chain of pain I can't insert the code since hasNoNextSong is unknown bolean at that time. I have apperantly older version, you are selling a new one. I could buy it, is upgrading painless, or it'll break everything? I did look into when the ending song should fire and it looks like this: private void CeaseAudioSource(AudioSource source) { Debug.Log("ceaseAudioSourceMethod"); if (source == null) { return; }
if (source == _activeAudio) { framesOfSongPlayed = 0; _activeSongAlias = null; }
var isValidClip = source.clip != null; source.Stop(); source.timeSamples = 0; // so it doesn't reset to last start time automatically. if (_transClip == null || _transClip.clip != source.clip) // don't unload audio if the same song is playing for crossfade { AudioUtil.UnloadNonPreloadedAudioData(source.clip, GameObj); }
AudioResourceOptimizer.UnloadPlaylistSongIfUnused(ControllerName, source.clip); source.clip = null; /// <========= this here will make it hard to fire event later
#if ADDRESSABLES_ENABLED if (_loadedAddressablesByAudioSource.ContainsKey(source)) { var addressable = _loadedAddressablesByAudioSource[source]; _loadedAddressablesByAudioSource.Remove(source); AudioAddressableOptimizer.RemoveAddressablePlayingClip(addressable, source); } #endif RemoveScheduledClip();
// only trigger the song ended event if we have actually ceased a valid audio clip // otherwise we trigger this event incorrectly the first time we start playing a playlist controller. if (!isValidClip) { return; }
var hasSongEndedEvent = songEndedEventExpanded && songEndedCustomEvent != string.Empty && songEndedCustomEvent != MasterAudio.NoGroupName; var hasSongEndedListener = SongEnded != null;
Debug.Log(hasSongEndedListener); // song ended start if (!hasSongEndedEvent && !hasSongEndedListener) { return; }
var songName = source.clip == null ? string.Empty : source.clip.CachedName();
if (string.IsNullOrEmpty(songName)) { Debug.Log("here"); // will always return here, i guess return; }
if (hasSongEndedEvent) { MasterAudio.FireCustomEvent(songEndedCustomEvent, Trans, false); }
if (hasSongEndedListener) { SongEnded(songName); } // song ended end
So ofc i tried commenting the source.clip = null; line out and yeah it will fire an event, but ofc it brakes actual audio playing, should i move firing of an event up the execution order ?
|
|
chunik
New Member
Posts: 17
Posts: 17
|
Post by chunik on Sept 27, 2022 5:15:26 GMT
Anyhow, even if i fixed the event firing, it had weird behavior, it fired too much, and crossfaded songs weirdly. What i did is when i start a song i just start my own timer, and before song ends i start a new one. If i'm controlling everything about playlist, make sense that i control song time also. But i still had buggy behavior until i unchecked fade out last song checkbox. (which might have been the issue with event also). Anyhow it works now. Wohooo Had to fight a little bit with your system though. Unlike other sounds, with songs it wasn't smooth. I couldn't find current elapsed time of the current song. Checking for fading out enums and clips was also strange, but it all might have been related to that checkbox which was messing everything up. Hopefully no more sound issues! Cheers.!
|
|
DarkTonic Dev
Administrator
Posts: 4,386
Posts: 4,386
Member is Online
|
Post by DarkTonic Dev on Sept 27, 2022 14:58:56 GMT
If you were to send me a Scene, you'd basically delete everything except the Master Audio / Playlist Controller game objects and any music scripts you wrote. I would not see your game code. I can't offer assistance with you fixing the code for your scenario as it may break other scenarios (there are a TON with the Playlists). There are too many settings for me to be able to reproduce it over descriptions. Really the only reliable way is for you to send me a Scene.
Current Elapsed time should be:
var elapsed = PlaylistController.InstancesByName("YourPlaylistControllerName").ActiveAudioSource.time;
Yes, upgrading to Master Audio 2022 is painless. There were a lot of bugs fixed as well.
|
|
chunik
New Member
Posts: 17
Posts: 17
|
Post by chunik on Sept 27, 2022 15:58:44 GMT
If you were to send me a Scene, you'd basically delete everything except the Master Audio / Playlist Controller game objects and any music scripts you wrote. I would not see your game code. I can't offer assistance with you fixing the code for your scenario as it may break other scenarios (there are a TON with the Playlists). There are too many settings for me to be able to reproduce it over descriptions. Really the only reliable way is for you to send me a Scene. Current Elapsed time should be: var elapsed = PlaylistController.InstancesByName("YourPlaylistControllerName").ActiveAudioSource.time;
Yes, upgrading to Master Audio 2022 is painless. There were a lot of bugs fixed as well. I'll get it, when it's on sale 80 Euro is a steep . Anyhow i'm unblocked now i have it working. And i think there is a bug in that method i posted, you first assign null to the clip. And then you return before firing event because songName will be empty string. How i fixed it i just move the line that gets songName up before you assign null. But i still had strange bugs, like event would fire, and i would tell it to play next song chosen by my code. And it would. Master audio would show it playing. But there was silence. Volume controls were correct but silence. And if i nudged playlist volume with a mouse it would go to normal. If i didn't nudge it and song would end in silence, the last second where it's supposed to fade out, i would actually hear. It was so strange. I came at it with different approaches, moving slider volume in code after i tell it to play a song . Listening for fading out enum change in update, and when it did i tell it to play next song, which had other bugs. What i ended up going for is just using my own time measurement, and a second before song ends i tell it to play another one. And it still wasn't working right until i unchecked that checkbox in the pic. Quite possible any of earlier solutions would have worked if i unchecked the box earlier, idk i didn't back track. It works now i'm happy .
|
|
DarkTonic Dev
Administrator
Posts: 4,386
Posts: 4,386
Member is Online
|
Post by DarkTonic Dev on Sept 27, 2022 19:50:34 GMT
Likely it was fixed in the newer plugin. There were a lot of PlaylistController bug fixes.
|
|