/// <summary> /// <para>Do NOT call this method directly! Use the <see cref="PlayManager"/> instead.</para> /// <para>Stops the old resource and starts the new one.</para> /// <para>The volume gets resetted and the OnStartEvent gets triggered.</para> /// </summary> /// <param name="playData">The info struct containing the PlayResource to start.</param> internal R StartResource(PlayResource playResource, MetaData config) { if (playResource == null) { Log.Write(Log.Level.Debug, "AF audioResource is null"); return("No new resource"); } Stop(true); if (string.IsNullOrWhiteSpace(playResource.PlayUri)) { return("Internal resource error: link is empty"); } Log.Write(Log.Level.Debug, "AF ar start: {0}", playResource); var result = playerConnection.AudioStart(playResource.PlayUri); if (!result) { Log.Write(Log.Level.Error, "Error return from player: {0}", result.Message); return($"Internal player error ({result.Message})"); } Volume = config.Volume ?? audioFrameworkData.DefaultVolume; Log.Write(Log.Level.Debug, "AF set volume: {0}", Volume); return(R.OkR); }
private E <LocalStr> StartResource(InvokerData invoker, PlayResource play, MetaData meta) { if (meta.From != PlaySource.FromPlaylist) { meta.ResourceOwnerUid = invoker.ClientUid; } var sourceLink = resourceFactory.RestoreLink(play.BaseData).OkOr(null); var playInfo = new PlayInfoEventArgs(invoker, play, meta, sourceLink); BeforeResourceStarted?.Invoke(this, playInfo); if (string.IsNullOrWhiteSpace(play.PlayUri)) { Log.Error("Internal resource error: link is empty (resource:{0})", play); return(new LocalStr(strings.error_playmgr_internal_error)); } Log.Debug("AudioResource start: {0}", play); var result = playerConnection.AudioStart(play); if (!result) { Log.Error("Error return from player: {0}", result.Error); return(new LocalStr(strings.error_playmgr_internal_error)); } playerConnection.Volume = Util.Clamp(playerConnection.Volume, confBot.Audio.Volume.Min, confBot.Audio.Volume.Max); CurrentPlayData = playInfo; // TODO meta as readonly AfterResourceStarted?.Invoke(this, playInfo); return(R.Ok); }
/// <summary> /// <para>Do NOT call this method directly! Use the FactoryManager instead.</para> /// <para>Stops the old resource and starts the new one.</para> /// <para>The volume gets resetted and the OnStartEvent gets triggered.</para> /// </summary> /// <param name="playData">The info struct contaiting the AudioResource to start.</param> /// <returns>An infocode on what happened.</returns> internal AudioResultCode StartResource(PlayData playData) { if (playData == null || playData.Resource == null) { Log.Write(Log.Level.Debug, "AF audioResource is null"); return(AudioResultCode.NoNewResource); } Stop(true); string resourceLink = playData.Resource.Play(); if (string.IsNullOrWhiteSpace(resourceLink)) { return(AudioResultCode.ResouceInternalError); } Log.Write(Log.Level.Debug, "AF ar start: {0}", playData.Resource); playerConnection.AudioStart(resourceLink); if (playData.Volume == -1) { Volume = audioFrameworkData.defaultVolume; } else { Volume = playData.Volume; } Log.Write(Log.Level.Debug, "AF set volume: {0}", Volume); OnResourceStarted?.Invoke(this, playData); CurrentPlayData = playData; if (!playerConnection.SupportsEndCallback) { endTime = Util.GetNow(); waitEndTick.Active = true; } return(AudioResultCode.Success); }