Ejemplo n.º 1
0
        private void Play()
        {
            try {
                TimeSpan now = new TimeSpan(DateTime.Now.Ticks);
                player.Play(now);

                while (player != null && !stopPlaying)
                {
                    lock (playerLock) {
                        if (player.Playing)
                        {
                            player.Update(now);
                            int scrollVal = (int)player.Elapsed.TotalSeconds;
                            if (scrollVal != scrSeek.Value)
                            {
                                SetScrollValue(scrollVal);
                            }
                        }
                        else
                        {
                            if (scrSeek.Value != 0)
                            {
                                SetScrollValue(0);
                            }
                        }
                    }
                    Thread.Sleep(1);
                    now = new TimeSpan(DateTime.Now.Ticks);
                }

                lock (playerLock) {
                    if (player.Playing)
                    {
                        player.Stop();
                        //Console.WriteLine("Closed while playing, stopPlaying: " + stopPlaying + ", player was null: " + (player == null));
                    }
                    else
                    {
                        //Console.WriteLine("Closed due to done playing");
                    }
                }
            }
#if DEBUG
            catch (Exception e) {
                Console.WriteLine("Background thread terminated: " + e.ToString());
            }
#else
            catch {
            }
#endif
            finally {
                player.CloseDevice();
                player = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Open a Text file
        /// </summary>
        private void OpenTextFile()
        {
            var diag = new OpenFileDialog();

            diag.InitialDirectory = ".";
            diag.Filter           = "Song files|*.mml;*.abc|MML files (*.mml)|*.mml|ABC files (*.abc)|*.abc|All files (*.*)|*.*";
            diag.FilterIndex      = filterIndex;
            diag.RestoreDirectory = true;

            Stream stream = null;

            if (diag.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((stream = diag.OpenFile()) != null)
                    {
                        //LoadFileIntoPlayer();
                        bPlayNow     = false;
                        bneverplayed = true;
                        LoadAsyncFile(diag.FileName);
                        lblFile.Text = "File: " + Path.GetFileName(diag.FileName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message + System.Environment.NewLine + ex.StackTrace);
                    if (player != null)
                    {
                        player.CloseDevice();
                    }
                }
            }

            filterIndex = diag.FilterIndex;
        }