private void BeforeResourceStarted(object sender, PlayInfoEventArgs e) { const string DefaultVoiceScript = "!whisper off"; const string DefaultWhisperScript = "!xecute (!whisper subscription) (!unsubscribe temporary) (!subscribe channeltemp (!getmy channel))"; var mode = AudioValues.audioFrameworkData.AudioMode; string script; if (mode.StartsWith("!", StringComparison.Ordinal)) { script = mode; } else if (mode.Equals("voice", StringComparison.OrdinalIgnoreCase)) { script = DefaultVoiceScript; } else if (mode.Equals("whisper", StringComparison.OrdinalIgnoreCase)) { script = DefaultWhisperScript; } else { Log.Error("Invalid voice mode"); return; } var info = CreateExecInfo(e.Invoker); CallScript(info, script, false, true); }
/// <summary>Plays the passed <see cref="PlayResource"/></summary> /// <param name="invoker">The invoker of this resource. Used for responses and association.</param> /// <param name="play">The associated resource type string to a factory.</param> /// <param name="meta">Allows overriding certain settings for the resource.</param> /// <returns>Ok if successful, or an error message otherwise.</returns> public E <LocalStr> Play(InvokerData invoker, PlayResource play, MetaData meta) { if (!meta.FromPlaylist) { meta.ResourceOwnerUid = invoker.ClientUid; } var playInfo = new PlayInfoEventArgs(invoker, play, meta); BeforeResourceStarted?.Invoke(this, playInfo); // pass the song to the AF to start it var result = StartResource(play, meta); if (!result) { return(result); } // add it to our freelist for comfort if (!meta.FromPlaylist) { int index = PlaylistManager.InsertToFreelist(new PlaylistItem(play.BaseData, meta)); PlaylistManager.Index = index; } CurrentPlayData = playInfo; // TODO meta as readonly AfterResourceStarted?.Invoke(this, CurrentPlayData); return(R.Ok); }
public void OnResourceStarted(object sender, PlayInfoEventArgs playData) { if (playData.Invoker.Channel.HasValue) { RestoreSubscriptions(playData.Invoker.Channel.Value); } }
public R Play(InvokerData invoker, PlayResource play, MetaData meta) { if (!meta.FromPlaylist) { meta.ResourceOwnerDbId = invoker.DatabaseId; } // add optional beforestart here. maybe for blocking/interrupting etc. BeforeResourceStarted?.Invoke(this, new EventArgs()); // pass the song to the AF to start it var result = AudioFramework.StartResource(play, meta); if (!result) { return(result); } // add it to our freelist for comfort if (!meta.FromPlaylist) { int index = PlaylistManager.InsertToFreelist(new PlaylistItem(play.BaseData, meta)); PlaylistManager.Index = index; } // Log our resource in the history ulong?owner = meta.ResourceOwnerDbId ?? invoker.DatabaseId; HistoryManager.LogAudioResource(new HistorySaveData(play.BaseData, owner)); CurrentPlayData = new PlayInfoEventArgs(invoker, play, meta); // TODO meta as readonly AfterResourceStarted?.Invoke(this, CurrentPlayData); return(R.OkR); }
private async Task AfterResourceStarted(object?sender, PlayInfoEventArgs e) { var onSongStart = config.Events.OnSongStart.Value; if (!string.IsNullOrEmpty(onSongStart)) { var info = CreateExecInfo(); await CallScript(info, onSongStart, false, true); } }
public void SongStoppedHook(object sender, SongEndEventArgs e) { BeforeResourceStopped?.Invoke(this, e); if (e.SongEndedByCallback && CurrentPlayData != null) { R result = Next(CurrentPlayData.Invoker); if (result) { return; } Log.Write(Log.Level.Warning, nameof(SongStoppedHook) + " could not play Next: " + result.Message); } CurrentPlayData = null; AfterResourceStopped?.Invoke(this, new EventArgs()); }
private void StopInternal(bool songEndedByCallback) { BeforeResourceStopped?.Invoke(this, new SongEndEventArgs(songEndedByCallback)); if (songEndedByCallback) { var result = Next(CurrentPlayData?.Invoker ?? InvokerData.Anonymous, false); if (result.Ok) { return; } Log.Info("Song queue ended: {0}", result.Error); } else { PlayerConnection.AudioStop(); } CurrentPlayData = null; AfterResourceStopped?.Invoke(this, EventArgs.Empty); }
private void Stop(bool songEndedByCallback = false) { BeforeResourceStopped?.Invoke(this, new SongEndEventArgs(songEndedByCallback)); if (songEndedByCallback && CurrentPlayData != null) { R result = Next(CurrentPlayData.Invoker); if (result) { return; } Log.Write(Log.Level.Warning, nameof(SongStoppedHook) + " could not play Next: " + result.Message); } else { PlayerConnection.AudioStop(); } CurrentPlayData = null; AfterResourceStopped?.Invoke(this, new EventArgs()); }
/// <summary>Plays the passed <see cref="PlayResource"/></summary> /// <param name="invoker">The invoker of this resource. Used for responses and association.</param> /// <param name="play">The associated resource type string to a factory.</param> /// <param name="meta">Allows overriding certain settings for the resource.</param> /// <returns>Ok if successful, or an error message otherwise.</returns> public E <LocalStr> Play(InvokerData invoker, PlayResource play, MetaData meta) { if (meta.From != PlaySource.FromPlaylist) { meta.ResourceOwnerUid = invoker.ClientUid; } var sourceLink = ResourceFactoryManager.RestoreLink(play.BaseData); var playInfo = new PlayInfoEventArgs(invoker, play, meta, sourceLink); BeforeResourceStarted?.Invoke(this, playInfo); var result = StartResource(play, meta); if (!result) { return(result); } CurrentPlayData = playInfo; // TODO meta as readonly AfterResourceStarted?.Invoke(this, playInfo); return(R.Ok); }
public void BeforeResourceStarted(object sender, PlayInfoEventArgs e) { var mode = AudioValues.audioFrameworkData.AudioMode; string script; if (mode.StartsWith("!", StringComparison.Ordinal)) { script = mode; } else if (mode.Equals("voice", StringComparison.OrdinalIgnoreCase)) { script = defaultVoiceScript; } else if (mode.Equals("whisper", StringComparison.OrdinalIgnoreCase)) { script = defaultWhisperScript; } else { Log.Write(Log.Level.Error, "Invalid voice mode"); return; } CallScript(script, e.Invoker); }