Example #1
0
        /// <summary>
        ///     Play an audio file globally, without position.
        /// </summary>
        /// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
        /// <param name="audioParams"></param>
        /// <param name="predicate">The predicate that will be used to send the audio to players, or null to send to everyone.</param>
        public AudioSourceServer PlayGlobal(string filename, AudioParams?audioParams = null, Func <IPlayerSession, bool>?predicate = null)
        {
            var id  = CacheIdentifier();
            var msg = new PlayAudioGlobalMessage
            {
                FileName    = filename,
                AudioParams = audioParams ?? AudioParams.Default,
                Identifier  = id
            };

            if (predicate == null)
            {
                RaiseNetworkEvent(msg);
                return(new AudioSourceServer(this, id));
            }

            var players = _playerManager.GetPlayersBy(predicate);

            foreach (var player in players)
            {
                RaiseNetworkEvent(msg, player.ConnectedClient);
            }

            return(new AudioSourceServer(this, id, players));
        }
Example #2
0
        /// <summary>
        ///     Play an audio file globally, without position.
        /// </summary>
        /// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
        /// <param name="audioParams"></param>
        /// <param name="predicate">The predicate that will be used to send the audio to players, or null to send to everyone.</param>
        /// <param name="excludedSession">Session that won't receive the audio message.</param>
        public AudioSourceServer PlayGlobal(string filename, AudioParams?audioParams = null, Func <IPlayerSession, bool>?predicate = null, IPlayerSession?excludedSession = null)
        {
            var id  = CacheIdentifier();
            var msg = new PlayAudioGlobalMessage
            {
                FileName    = filename,
                AudioParams = audioParams ?? AudioParams.Default,
                Identifier  = id
            };

            if (predicate == null && excludedSession == null)
            {
                RaiseNetworkEvent(msg);
                return(new AudioSourceServer(this, id));
            }

            var players = predicate != null?_playerManager.GetPlayersBy(predicate) : _playerManager.GetAllPlayers();

            for (var i = players.Count - 1; i >= 0; i--)
            {
                var player = players[i];
                if (player == excludedSession)
                {
                    players.RemoveAt(i);
                    continue;
                }

                RaiseNetworkEvent(msg, player.ConnectedClient);
            }

            return(new AudioSourceServer(this, id, players));
        }
Example #3
0
        private void PlayAudioGlobalHandler(PlayAudioGlobalMessage ev)
        {
            var stream = (PlayingStream?)Play(ev.FileName, ev.AudioParams);

            if (stream != null)
            {
                stream.NetIdentifier = ev.Identifier;
            }
        }
        /// <summary>
        ///     Play an audio file globally, without position.
        /// </summary>
        /// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
        public void Play(string filename, AudioParams?audioParams = null)
        {
            var msg = new PlayAudioGlobalMessage
            {
                FileName    = filename,
                AudioParams = audioParams ?? AudioParams.Default
            };

            RaiseNetworkEvent(msg);
        }
        /// <inheritdoc />
        public IPlayingAudioStream Play(Filter playerFilter, string filename, AudioParams?audioParams = null)
        {
            var id  = CacheIdentifier();
            var msg = new PlayAudioGlobalMessage
            {
                FileName    = filename,
                AudioParams = audioParams ?? AudioParams.Default,
                Identifier  = id
            };

            RaiseNetworkEvent(msg, playerFilter);

            return(new AudioSourceServer(this, id, playerFilter.Recipients.ToArray()));
        }
Example #6
0
        /// <inheritdoc />
        public IPlayingAudioStream Play(Filter playerFilter, string filename, AudioParams?audioParams = null)
        {
            var id  = CacheIdentifier();
            var msg = new PlayAudioGlobalMessage
            {
                FileName    = filename,
                AudioParams = audioParams ?? AudioParams.Default,
                Identifier  = id
            };

            var players = (playerFilter as IFilter).Recipients;

            foreach (var player in players)
            {
                RaiseNetworkEvent(msg, player.ConnectedClient);
            }

            return(new AudioSourceServer(this, id, players));
        }
Example #7
0
 private void PlayAudioGlobalHandler(PlayAudioGlobalMessage ev)
 {
     Play(ev.FileName, ev.AudioParams);
 }