Ejemplo n.º 1
0
        /// <summary>
        /// Plays a sound file on the brick at a given volume and at certain interval
        /// The sound file must be stored in BrickFolder.Projects and in FolderName
        /// </summary>
        /// <param name="soundFile">A playable soundfile
        /// </param>
        /// <param name="volume">Specify volume for playback, [0 - 100]</param>
        /// <param name="numberOfLoops">Specify number of loops [1-n], 1 will play soundfile once</param>
        /// <param name="timeOut">Time in milliseconds between plays [0-n]</param>
        /// <exception cref="ArgumentOutOfRangeException">volume, numberOfLoops or timeOut out of range</exception>
        public async void PlayLoop(SoundFile soundFile, int volume, int numberOfLoops, int timeOut)
        {
            if (timeOut < 0)
            {
                throw new ArgumentException("Time out must >= 0 ms", "timeOut");
            }
            if (numberOfLoops < 1)
            {
                throw new ArgumentException("Amount must be > 0", "numberOfLoops");
            }

            if (numberOfLoops == 1)
            {
                await SoundMethods.Play(Brick.Socket, volume, soundFile.FilePath);
            }
            else
            {
                CancellationToken token = Brick.Socket.CancellationToken;
                await Task.Factory.StartNew(
                    async() =>
                {
                    for (int i = 0; i < numberOfLoops; i++)
                    {
                        await SoundMethods.Play(Brick.Socket, volume, soundFile.FilePath);
                        while (await IsBusy())    // test if file is still playing
                        {
                            token.WaitHandle.WaitOne(500);
                        }
                        if (i + 1 < numberOfLoops)    // only pause between sounds
                        {
                            if (token.WaitHandle.WaitOne(timeOut))
                            {
                                break;
                            }
                        }
                    }
                }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Plays a sound file on the brick at a given volume.
 /// The sound file must be stored in BrickFolder.Projects and in FolderName
 /// </summary>
 /// <param name="soundFile">A playable soundfile
 /// </param>
 /// <param name="volume">Specify volume for playback, [0 - 100]</param>
 /// <exception cref="ArgumentOutOfRangeException">volume out of range</exception>
 public async void Play(SoundFile soundFile, int volume)
 {
     await SoundMethods.Play(Brick.Socket, volume, soundFile.FilePath);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Repeats playing a sound file on the brick at a given volume untill Stop() is called
 /// </summary>
 /// <param name="soundFile">A playable soundfile
 /// </param>
 /// <param name="volume">Specify volume for playback, [0 - 100]</param>
 /// <exception cref="ArgumentOutOfRangeException">volume out of range</exception>
 public async void Repeat(SoundFile soundFile, int volume)
 {
     await SoundMethods.Repeat(Brick.Socket, volume, soundFile.FilePath);
 }