mush
New Member
Posts: 39
Posts: 39
|
Post by mush on Apr 17, 2015 22:14:20 GMT
Hello - loving Master Audio
how do i get current clip title?
if have tried
songTitle = PlaylistController.InstanceByName("PlaylistControllerOrchestra").ActiveAudioSource.clipName
and various other clip.text etc but cannot work it out
Best regards, Chris
|
|
|
Post by DarkTonic Dev on Apr 18, 2015 5:50:45 GMT
You almost had it, unless you did a typo there. Missing a dot before name at the end.
var songTitle = PlaylistController.InstanceByName("PlaylistControllerOrchestra").ActiveAudioSource.clip.name;
|
|
mush
New Member
Posts: 39
Posts: 39
|
Post by mush on Apr 18, 2015 12:04:34 GMT
hahaha - i tried everything except the obvious - thanks heaps - that worked perfectly
|
|
|
Post by DarkTonic Dev on Apr 18, 2015 18:54:38 GMT
No problem.
|
|
mush
New Member
Posts: 39
Posts: 39
|
Post by mush on Apr 18, 2015 20:12:47 GMT
Actually something strange is happening - it displays the correct song for about 1 second then it displays another song title from playlist. I have songs loaded as clips which have a custom event on song ended - which plays a random song. My custom event name is "PlayNextSong" - this does not clash with any Master Audio references does it?
|
|
mush
New Member
Posts: 39
Posts: 39
|
Post by mush on Apr 18, 2015 20:18:38 GMT
This is the ReceiveEvent function in my MA_CustomEventReciever file:
public void ReceiveEvent(string customEventName, Vector3 originPoint) { switch (customEventName) { case "PlayerMoved": Debug.Log("PlayerMoved event recieved by '" + name + "'."); break; case "PlayerStoppedMoving": Debug.Log("PlayerStoppedMoving event recieved by '" + name + "'."); break; case "PlayAnotherSong": Debug.Log("PlayAnotherSong event recieved by '" + name + "'."); if(Application.loadedLevel == 1 || Application.loadedLevel == 2) MasterAudio.TriggerPlaylistClip("TitleMusic"); //MasterAudio.StartPlaylist("Orchestra"); else { random = Random.Range(1,17); if(random > 16) MasterAudio.TriggerPlaylistClip("Alleyuma"); else if(random > 15) MasterAudio.TriggerPlaylistClip("Bamrantoo"); else if(random > 14) MasterAudio.TriggerPlaylistClip("Culapino"); else if(random > 13) MasterAudio.TriggerPlaylistClip("Dope"); else if(random > 12) MasterAudio.TriggerPlaylistClip("Enuyirop"); else if(random > 11) MasterAudio.TriggerPlaylistClip("Fantyum"); else if(random > 10) MasterAudio.TriggerPlaylistClip("Grillin'"); else if(random > 9) MasterAudio.TriggerPlaylistClip("Hi You"); else if(random > 8) MasterAudio.TriggerPlaylistClip("Pluntou"); else if(random > 7) MasterAudio.TriggerPlaylistClip("Sanuyer"); else if(random > 6) MasterAudio.TriggerPlaylistClip("Sketza Short Mix 1"); else if(random > 5) MasterAudio.TriggerPlaylistClip("Somethin'"); else if(random > 4) MasterAudio.TriggerPlaylistClip("Surenger MIX 2"); else if(random > 3) MasterAudio.TriggerPlaylistClip("Tillard"); else if(random > 2) MasterAudio.TriggerPlaylistClip("Tyonu"); else MasterAudio.TriggerPlaylistClip("Yearyu - 122");
}
break; } }
|
|
mush
New Member
Posts: 39
Posts: 39
|
Post by mush on Apr 18, 2015 20:20:05 GMT
Sorry i am not sure what happened - when i submitted the above code via the Post Quick Reply button - the code lost all its formatting.
|
|
|
Post by DarkTonic Dev on Apr 19, 2015 3:22:04 GMT
Actually something strange is happening - it displays the correct song for about 1 second then it displays another song title from playlist. I have songs loaded as clips which have a custom event on song ended - which plays a random song. My custom event name is "PlayNextSong" - this does not clash with any Master Audio references does it? There are no "built in" Custom Events so it doesn't matter what you name yours. The code I posted will work until a song starts crossfading into another song, at which point the new song (the one fading in) will be displayed instead. You also would need to add a null check in case "clip" is null (may happen if Playlist was stopped). If you determine that something different is happening, you can send me a stripped down project that reproduces the problem. -Brian
|
|
mush
New Member
Posts: 39
Posts: 39
|
Post by mush on Apr 19, 2015 18:12:09 GMT
Thanks - turning off the cross fading worked great
|
|
|
Post by DarkTonic Dev on Apr 19, 2015 18:58:40 GMT
Awesome.
|
|
mush
New Member
Posts: 39
Posts: 39
|
Post by mush on Apr 20, 2015 11:59:07 GMT
Hello - i have swapped from clip to resource mode for my playlist because it has grown to big to hold all in memory. I haved changed my songs to stream - so all good there (no slight pause now ) but I cannot get custom songendevent to fire now - does it only work in clip mode?
I previously had my MA_CustomEventReciever file attached to the maincam or levelsettings module in each scene - can i just attach it to my playlistcontroller since it will be persistant and not have to attach it anywhere else in program?
Also how to i check for null on this statement? var songTitle = PlaylistController.InstanceByName("PlaylistControllerOrchestra").ActiveAudioSource.clip.name;
Best regards, Chris
|
|
|
Post by DarkTonic Dev on Apr 20, 2015 14:51:34 GMT
SongEnded still works for me with Resource files. Sample code I used was the following in Unity 5:
PlaylistController.Instances[0].SongEnded += delegate { Debug.Log("next: " + Time.frameCount); };
By the way, SongEnded has nothing to do with Custom Events. Maybe you are confused?
Null check like this:
var songClip = PlaylistController.InstanceByName("PlaylistControllerOrchestra").ActiveAudioSource.clip; var songTitle = ""; if (songClip != null) { songTitle = clip.name; }
|
|
mush
New Member
Posts: 39
Posts: 39
|
Post by mush on Apr 20, 2015 20:23:42 GMT
Confused is one thing - but to be confused and not knowing that you are is far worse I had been using the Song Ended custom event the whole time and then adding the my CustomEventReciever to every scene. Your method of using a delegate is not only easier but is less resource hungry. Now I simply have a StartGameMusic script on each game level which calls the MasterAudio.TriggerPlaylistClip("WhateverSongIwant") and then adds the delegate underneath this call. So far so good - thanks very much for all your help, your quick responses and most of all your patience. Best regards, Chris
|
|
|
Post by DarkTonic Dev on Apr 20, 2015 22:01:57 GMT
Ok sounds good!
|
|