Esempio n. 1
0
        private void PlayListPlayThread(MediaEntry mediaEntry, int priority)
        {
            _currentPlayList = new CurrentPlayList(mediaEntry.Name, mediaEntry.Shuffle);

            var single = new MediaEntry
            {
                EndTime = mediaEntry.EndTime,
                Every = mediaEntry.Every,
                NextEligibility = mediaEntry.NextEligibility,
                PlayDate = mediaEntry.PlayDate,
                PlayDay = mediaEntry.PlayDay,
                PlayUntil = mediaEntry.PlayUntil,
                RepeatCount = 0, //mediaEntry.RepeatCount,
                Shuffle = mediaEntry.Shuffle,
                StartTime = mediaEntry.StartTime,
                Type = mediaEntry.Type
            };

            _currentPlayList.GetNextSongFileName(ref single.Name, ref single.AfterPlayPauseInSeconds);

            _currentMedia = null; // KILL
            try
            {
                for (int i = 0; i <= mediaEntry.RepeatCount && _currentPlayList != null; i++)
                {
                    do
                    {
                        Play(single, priority);
                        // Wait as long the song in playing
                        while (!AudioModule.Idle)
                        {
                            Thread.Sleep(100);
                        }
                        if (_currentPlayList == null)
                            return;

                        // If defined by the user, insert a pause before next song to play.
                        if (single.AfterPlayPauseInSeconds != 0)
                        {
                            // check every 100mSec for user stop request
                            int countDown = single.AfterPlayPauseInSeconds*10;
                            while (_currentPlayList != null)
                            {
                                Thread.Sleep(100);
                                if (--countDown < 0)
                                {
                                    break;
                                }
                                DebugHelper.Print(countDown.ToString());
                            }
                        }

                        _currentPlayList.GetNextSongFileName(ref single.Name, ref single.AfterPlayPauseInSeconds);
                        // single.Name = _currentPlayList.GetNextSongFileName();
                    } while (single.Name != "");

                    if (mediaEntry.RepeatCount > 0)
                    {
                        if (mediaEntry.Shuffle)
                        {
                            _currentPlayList.ReShuffle();
                        }
                        else
                        {
                            _currentPlayList.ResetList();
                        }
                        //single.Name = _currentPlayList.GetNextSongFileName();
                        _currentPlayList.GetNextSongFileName(ref single.Name, ref single.AfterPlayPauseInSeconds);
                    }
                }
            }
            catch
            {
                ;
            }
        }
Esempio n. 2
0
        public void Stop(MediaEntry toStop = null)
        {
            try
            {
                if (toStop != null && toStop != _currentMedia)
                {
                    DebugHelper.DebugPrint("Audiocore.Stop() : Nothing to stop");
                    return;
                }

                DebugHelper.Print("Audiocore.Stop()");
                _currentPlayList = null; // this prevent to start a new song from the playlist in onMusicFinished()

                AudioModule.StopPlay();
                OnNowPlaying("");

                if (_currentStream != null)
                {
                    _currentStream.Close();
                    _currentStream.Dispose();
                    _currentStream = null;
                }
                _currentMedia = null;
            }
            catch (Exception ex)
            {
                Log.WriteException(ex, "!!!!!!!!!!!!!!!!!!!");
                _currentMedia = null; // B73: To make sure the next schedule is not rejected
            }
        }