/// <summary> /// When the play button is clicked, start playing teh sound /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void play_Click(object sender, EventArgs e) { // Play sound var item = comboBox1.SelectedItem; // Look up the id for the selected sound. For obvious reasons, we // try to display the text name, if we have one -- we usually don't -- // so that needs to be converted back into an ID uint id; if (item is string name) { id = AudioAssets.IDForString(name); } else { id = (uint)item; } // Open the WEM stream for the id var WEM = audioAssets.WEM(id); if (null == WEM) { return; } // Stop whatever was playing waveOut.Stop(); // Start the new stuff waveOut.Init(WEM.WaveProvider()); waveOut.Play(); }
internal static IEnumerator PlaySound(Enums.AudioSounds audioType, Action onMusicStopPlay) { if (Level.GetInstance.GameFinished) { yield break; } GameObject _gameObj = audioSoundsGameObjects.Dequeue(); AudioSource audioSource = _gameObj.GetComponent <AudioSource>(); if (AudioAssets.GetInstance().GetSound(audioType) != null) { if (audioType == Enums.AudioSounds.BackGroundMusic) { backMusic = audioSource; } audioSource.clip = AudioAssets.GetInstance().GetSound(audioType); _gameObj.SetActive(true); audioSource.Play(); } currentPlaingAudioSounds.Add(audioSource); yield return(new WaitWhile(() => audioSource.isPlaying)); currentPlaingAudioSounds.Remove(audioSource); audioSoundsGameObjects.Enqueue(audioSource.gameObject); audioSource.gameObject.SetActive(false); onMusicStopPlay?.Invoke(); }
/// <summary> /// When the human presses the open button, show a file dialog to open /// the right thing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { using var fbd = new FolderBrowserDialog(); DialogResult result = fbd.ShowDialog(); if (result != DialogResult.OK || string.IsNullOrWhiteSpace(fbd.SelectedPath)) { return; } // Open the assets // (You should put a lot more error checking here!) assets = new Assets(fbd.SelectedPath); comboBox1.Items.Clear(); audioAssets = assets.AudioAssets; // List the files // First list each of the sound banks foreach (var soundBankName in audioAssets.SoundBankNames) { // Get the sound bank var soundBank = audioAssets.SoundBank(soundBankName); // Get the sounds in the soundbank foreach (var fileInfo in soundBank.Sounds) { // See if the name for the sound id is known // (Spoiler: it usually isn't) object id = AudioAssets.StringForID(fileInfo.ID); if (null == id) { id = fileInfo.ID; } // Because the libary is still new, it reports things it // thinks are WEM resources.. but are not. Still working // out how better to resolve that. This next step screens // out the bogus ones for now. if (0 == fileInfo.Size && 0 == fileInfo.PrefetchSize) { continue; } #if false // Open the WEM stream for the id.. to check that it's real var WEM = audioAssets.WEM(fileInfo.ID); if (null == WEM) { continue; } WEM.Dispose(); #endif // And put it in the combo list comboBox1.Items.Add(id); } } comboBox1.SelectedIndex = 0; }
private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } }
void Awake() { playerMovementInput = new Vector3(); viewport = GetComponentInChildren<Camera>(); flashLight = GetComponent<Light>(); audioAssets = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<AudioAssets>(); try { levelController = GameObject.FindGameObjectWithTag(Tags.levelController).GetComponent<MainLevelController>(); }catch(Exception e) { Debug.Log(e); } }
public override void Initialize() { Node.size = Globals.TILE_WIDTH; Globals.diamonds = 0; Globals.soundManager = new SoundManager(); ArtAssets.LoadTextures(); ArtAssets.LoadFont(Globals.contentManager); AudioAssets.Load(Globals.contentManager); AnimationAssets.LoadAnimations(Globals.graphicsDevice, Globals.contentManager); Armies.SetUpCharacters(); StateManager.ChangeState(Settings.STATES.MainMenu); }
private void PopulateAssets(AudioAssets assets) { if (assets == null) { return; } if (assets.musics != null) { foreach (AudioClip a in assets.musics) { m_AssetsNames[a.name] = a; } } if (assets.soundEffects != null) { foreach (AudioClip a in assets.soundEffects) { m_AssetsNames[a.name] = a; } } }
void Awake() { // Zuweisung von Variablen #region npcSight = GetComponent<NPC_Sight>(); nav = GetComponent<NavMeshAgent>(); col = GetComponent<SphereCollider>(); player = GameObject.FindGameObjectWithTag(Tags.player).transform; playerHealth = player.GetComponent<Player_Health>(); playerMovement = player.GetComponent<Player_Movement>(); audioAssets = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<AudioAssets>(); alert = 0f; waitTimer = 0f; #endregion // Zuweisung der Delegaten #region PlayerTracker.Stepped += ReactToStep; PlayerTracker.Jumped += ReactToJump; PlayerTracker.ShotFired += ReactToShot; PlayerTracker.DoorMoved += ReactToDoorSound; #endregion }
private void Awake() { instance = this; }
protected override void OnStartRunning() { RequireSingletonForUpdate <AudioAssets>(); audioAssets = GetSingleton <AudioAssets>(); base.OnStartRunning(); }
public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context) { var log = context.Logger; // I use the following lines to log and validate my input // but this isn't a requirement for the skill //log.LogLine($"Skill Request Object..."); //log.LogLine(JsonConvert.SerializeObject(input)); SkillResponse returnResponse = new SkillResponse(); var audioItems = AudioAssets.GetSampleAudioFiles(); // initialize a connection to the database // this also initialized the context for the DynamoDB helper var audioStateHelper = new AudioStateHelper(); await audioStateHelper.VerifyTable(); string userId = ""; if (input.Session != null) { userId = input.Session.User.UserId; } else { userId = input.Context.System.User.UserId; } var lastState = await audioStateHelper.GetAudioState(userId); var currentState = new AudioState() { UserId = userId }; currentState.State = lastState.State; // For an intent if (input.GetRequestType() == typeof(LaunchRequest)) { log.LogLine($"Default LaunchRequest made"); var output = new PlainTextOutputSpeech() { Text = "Welcome to the Alexa audio sample. " + "You can say, play the audio, to begin." }; var reprompt = new Reprompt() { OutputSpeech = new PlainTextOutputSpeech() { Text = "You can say, play the audio, to begin." } }; returnResponse = ResponseBuilder.Ask(output, reprompt); await audioStateHelper.SaveAudioState(currentState); } else if (input.GetRequestType() == typeof(IntentRequest)) { var intentRequest = (IntentRequest)input.Request; var output = new PlainTextOutputSpeech(); var reprompt = new Reprompt(); log.LogLine($"Triggered " + intentRequest.Intent.Name); switch (intentRequest.Intent.Name) { case "PlayAudio": currentState.State.Token = audioItems.FirstOrDefault().Title; currentState.State.State = "PLAY_MODE"; currentState.State.Index = 0; currentState.State.playOrder = new List <int> { 0, 1, 2, 3, 4 }; returnResponse = ResponseBuilder.AudioPlayerPlay( PlayBehavior.ReplaceAll, audioItems[currentState.State.Index].Url, currentState.State.Token); break; case BuiltInIntent.Help: output.Text = "You can say, play the audio, to begin."; reprompt.OutputSpeech = new PlainTextOutputSpeech() { Text = "You can say, play the audio, to begin." }; returnResponse = ResponseBuilder.Ask(output, reprompt); break; case BuiltInIntent.Cancel: currentState.State.OffsetInMS = Convert.ToInt32(input.Context.AudioPlayer.OffsetInMilliseconds); currentState.State.Token = input.Context.AudioPlayer.Token; currentState.State.State = "PAUSE_MODE"; returnResponse = ResponseBuilder.AudioPlayerStop(); break; case BuiltInIntent.Next: var thisFile = lastState.State.Token; // get the last state, get the index, add 1 // or start from the beginning if you're doing a loop currentState.State.Index++; if (currentState.State.Index >= audioItems.Count) { currentState.State.Index = 0; } currentState.State.Token = audioItems[currentState.State.Index].Title; currentState.State.OffsetInMS = 0; currentState.State.State = "PLAY_MODE"; returnResponse = ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioItems[currentState.State.Index].Url, currentState.State.Token); break; case BuiltInIntent.Previous: // get the last state, get the index, subtract 1 currentState.State.Index = currentState.State.Index - 1; if (currentState.State.Index < 0) { currentState.State.Index = 0; } currentState.State.Token = audioItems[currentState.State.Index].Title; currentState.State.OffsetInMS = 0; currentState.State.State = "PLAY_MODE"; returnResponse = ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioItems[currentState.State.Index].Url, currentState.State.Token); break; case BuiltInIntent.Repeat: // get the last state, get the index, start over at offset = 0 currentState.State.Token = audioItems[currentState.State.Index].Title; currentState.State.OffsetInMS = 0; currentState.State.State = "PLAY_MODE"; returnResponse = ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioItems[currentState.State.Index].Url, currentState.State.Token, 0); break; case BuiltInIntent.StartOver: // start everything from the beginning currentState.State.Token = audioItems[0].Title; currentState.State.OffsetInMS = 0; currentState.State.State = "PLAY_MODE"; returnResponse = ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioItems[0].Url, currentState.State.Token, 0); break; case BuiltInIntent.Stop: currentState.State.OffsetInMS = Convert.ToInt32(input.Context.AudioPlayer.OffsetInMilliseconds); currentState.State.Token = input.Context.AudioPlayer.Token; currentState.State.State = "PAUSE_MODE"; returnResponse = ResponseBuilder.AudioPlayerStop(); break; case BuiltInIntent.Resume: // Get the last state, start from the offest in milliseconds returnResponse = ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioItems[currentState.State.Index].Url, currentState.State.Token, currentState.State.OffsetInMS); // If there was an enqueued item... if (currentState.State.EnqueuedToken != null) { returnResponse.Response.Directives.Add(new AudioPlayerPlayDirective() { PlayBehavior = PlayBehavior.Enqueue, AudioItem = new Alexa.NET.Response.Directive.AudioItem() { Stream = new AudioItemStream() { Url = audioItems[currentState.State.Index + 1].Url, Token = audioItems[currentState.State.Index + 1].Title, ExpectedPreviousToken = currentState.State.Token, OffsetInMilliseconds = 0 } } }); } currentState.State.EnqueuedToken = audioItems[currentState.State.Index + 1].Title; currentState.State.State = "PLAY_MODE"; break; case BuiltInIntent.Pause: currentState.State.OffsetInMS = Convert.ToInt32(input.Context.AudioPlayer.OffsetInMilliseconds); currentState.State.Token = input.Context.AudioPlayer.Token; currentState.State.State = "PAUSE_MODE"; returnResponse = ResponseBuilder.AudioPlayerStop(); break; default: log.LogLine($"Unknown intent: " + intentRequest.Intent.Name); output.Text = "Welcome to Pocast Player"; reprompt.OutputSpeech = new PlainTextOutputSpeech() { Text = "This is your reprompt. Please do something." }; returnResponse = ResponseBuilder.TellWithReprompt(output, reprompt); break; } } else if (input.GetRequestType() == typeof(AudioPlayerRequest)) { var audioRequest = input.Request as AudioPlayerRequest; if (audioRequest.AudioRequestType == AudioRequestType.PlaybackStarted) { log.LogLine($"PlaybackStarted Triggered "); // respond with Stop or ClearQueue returnResponse = ResponseBuilder.AudioPlayerClearQueue(ClearBehavior.ClearEnqueued); } else if (audioRequest.AudioRequestType == AudioRequestType.PlaybackFinished) { // Audio comes to an end on its own log.LogLine($"PlaybackFinished Triggered "); if (currentState.State.EnqueuedToken != null) { int itemIndex = audioItems.IndexOf(audioItems.Where(i => i.Title == currentState.State.EnqueuedToken).FirstOrDefault()); currentState.State.Token = audioItems[itemIndex].Title; currentState.State.Index = itemIndex; returnResponse = ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioItems[itemIndex].Url, currentState.State.Token); } else { // respond with Stop or ClearQueue returnResponse = ResponseBuilder.AudioPlayerClearQueue(ClearBehavior.ClearEnqueued); } } else if (audioRequest.AudioRequestType == AudioRequestType.PlaybackStopped) { // This is when your audio is explicitly stopped log.LogLine($"PlaybackStopped Triggered "); currentState.State.State = "PAUSE_MODE"; currentState.State.Token = audioRequest.Token; currentState.State.EnqueuedToken = audioRequest.EnqueuedToken; currentState.State.OffsetInMS = Convert.ToInt32(audioRequest.OffsetInMilliseconds); log.LogLine($"Saving AudioState: " + currentState.State.Token + " at " + currentState.State.OffsetInMS.ToString() + "ms"); returnResponse = null; } else if (audioRequest.AudioRequestType == AudioRequestType.PlaybackNearlyFinished) { log.LogLine($"PlaybackNearlyFinished Triggered "); // we'll want to hand back the "next" item in the queue // First we check to see if there is an enqueued item and, if there is // we can respond with nothing if (audioRequest.HasEnqueuedItem) { return(null); } // let's get the current token var currentPlay = audioRequest.Token; // get the index of that current item int itemIndex = audioItems.IndexOf(audioItems.Where(i => i.Title == audioRequest.Token).FirstOrDefault()); if (itemIndex == -1) { log.LogLine($"Could not get the index of: " + audioRequest.Token); } itemIndex++; if (itemIndex == audioItems.Count) { itemIndex = 0; } currentState.State.EnqueuedToken = audioItems[itemIndex].Title; currentState.State.Token = audioRequest.Token; // if there is not, we send a play intent with "ENQUEUE" returnResponse = ResponseBuilder.AudioPlayerPlay( PlayBehavior.Enqueue, audioItems[itemIndex].Url, currentState.State.EnqueuedToken, currentState.State.Token, 0); } else if (audioRequest.AudioRequestType == AudioRequestType.PlaybackFailed) { log.LogLine($"PlaybackFailed Triggered"); // atm, we basically pretend nothing happened and play the first // file again on a failure // THIS IS A TERRIBLE SOLUTION // Figure out a better one for your skill currentState.State.Token = audioItems.FirstOrDefault().Title; currentState.State.Index = 0; currentState.State.State = "PLAY_MODE"; returnResponse = ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioItems.FirstOrDefault().Url, currentState.State.Token); } } // I use the following code to validate and log my outputs for // later investigation //log.LogLine($"Skill Response Object..."); //string responseJson = "no response is given"; //try //{ // responseJson = JsonConvert.SerializeObject(returnResponse); //} //catch //{ // log.LogLine(responseJson); // return null; //} //log.LogLine(responseJson); // Save our state await audioStateHelper.SaveAudioState(currentState); // return our response return(returnResponse); }
public void Play(string name) { AudioAssets s = Array.Find(sounds, sound => sound.name == name); s.source.Play(); }