/// <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 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); }