public void Start(string fileName, int KaraokeId, string message, string messageAtEnd)
        {
            stopPlay       = false;
            cdgFile        = new CDGFile(fileName);
            this.currentId = KaraokeId;
            var mp3FileName = fileName.Replace(System.IO.Path.GetExtension(fileName), ".mp3");

            cdgLength = cdgFile.getTotalDuration();
            PlayMp3File(mp3FileName);
            startTime       = DateTime.Now;
            firstFrame      = false;
            endTime         = startTime.AddMilliseconds(cdgLength);
            msecsRemaining  = cdgLength;
            timer           = new System.Windows.Threading.DispatcherTimer();
            timer.Tick     += new EventHandler(TickTimer);
            txtAnuncio.Text = message;
            messageEnd      = messageAtEnd;
            step1           = true;
            step2           = false;


            txtAnuncio.Visibility = System.Windows.Visibility.Visible;
            timer.Interval        = new TimeSpan(0, 0, 0, 0, 100);
            timer.Start();
        }
示例#2
0
        private void btSelectFile_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                edFilename.Text = openFileDialog1.FileName;

                if (cdg != null)
                {
                    cdg.Dispose();
                    cdg = null;
                }

                var cdgFile = Path.Combine(Path.GetDirectoryName(edFilename.Text), Path.GetFileNameWithoutExtension(edFilename.Text)) + ".cdg";
                if (File.Exists(cdgFile))
                {
                    cdg = new CDGFile(cdgFile);
                }
            }
        }
        public void Start(string fileName)
        {
            int frameCount = 0;

            stopPlay = false;
            cdgFile  = new CDGFile(fileName);

            var mp3FileName = fileName.Replace(System.IO.Path.GetExtension(fileName), ".mp3");

            cdgLength = cdgFile.getTotalDuration();
            PlayMp3File(mp3FileName);
            startTime      = DateTime.Now;
            endTime        = startTime.AddMilliseconds(cdgLength);
            msecsRemaining = cdgLength;
            timer          = new System.Windows.Threading.DispatcherTimer();
            timer.Tick    += new EventHandler(TickTimer);

            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            timer.Start();
            //while (msecsRemaining > 0)
            //{
            //    if (stopPlay)
            //    {
            //        break;
            //    }
            //    msecsRemaining = (long)endTime.Subtract(DateTime.Now).TotalMilliseconds;
            //    var pos = cdgLength - msecsRemaining;
            //    while (pausePlay)
            //    {
            //        endTime = DateTime.Now.AddMilliseconds(msecsRemaining);

            //        System.Windows.Forms.Application.DoEvents();
            //    }
            //    cdgFile.renderAtPosition(pos);
            //    ++frameCount;
            //    canvas.Image = cdgFile.get_RGBImage(false);
            //    canvas.BackColor = ((System.Drawing.Bitmap)canvas.Image).GetPixel(1, 1);
            //    canvas.Refresh();
            //    System.Windows.Forms.Application.DoEvents();
            //}
            //StopCdgFile();
        }
示例#4
0
        public void PlayCdg(string fileName, System.Windows.Forms.PictureBox canvas)
        {
            int frameCount = 0;

            stopPlay = false;
            cdgFile  = new CDGFile(fileName);
            var mp3FileName = fileName.Replace(Path.GetExtension(fileName), ".mp3");
            var cdgLength   = cdgFile.getTotalDuration();

            PlayMp3File(mp3FileName);
            var startTime      = DateTime.Now;
            var endTime        = startTime.AddMilliseconds(cdgLength);
            var msecsRemaining = cdgLength;

            while (msecsRemaining > 0)
            {
                if (stopPlay)
                {
                    break;
                }
                msecsRemaining = (long)endTime.Subtract(DateTime.Now).TotalMilliseconds;
                var pos = cdgLength - msecsRemaining;
                while (pausePlay)
                {
                    endTime = DateTime.Now.AddMilliseconds(msecsRemaining);
                    System.Windows.Forms.Application.DoEvents();
                }
                cdgFile.renderAtPosition(pos);
                ++frameCount;
                canvas.Image     = cdgFile.get_RGBImage(false);
                canvas.BackColor = ((System.Drawing.Bitmap)canvas.Image).GetPixel(1, 1);
                canvas.Refresh();
                System.Windows.Forms.Application.DoEvents();
            }
            StopCdgFile();
        }
        public void Start(string fileName, int KaraokeId, string message, string messageAtEnd)
        {
            stopPlay = false;
            cdgFile = new CDGFile(fileName);
            this.currentId = KaraokeId;
            var mp3FileName = fileName.Replace(System.IO.Path.GetExtension(fileName), ".mp3");
            cdgLength = cdgFile.getTotalDuration();
            PlayMp3File(mp3FileName);
            startTime = DateTime.Now;
            firstFrame = false;
            endTime = startTime.AddMilliseconds(cdgLength);
            msecsRemaining = cdgLength;
            timer = new System.Windows.Threading.DispatcherTimer();
            timer.Tick += new EventHandler(TickTimer);
            txtAnuncio.Text = message;
            messageEnd = messageAtEnd;
            step1 = true;
            step2 = false;

            txtAnuncio.Visibility = System.Windows.Visibility.Visible;
            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            timer.Start();
        }
示例#6
0
        public void CDGtoAVI(string aviFileName, string cdgFileName, string mp3FileName, double frameRate, string backgroundFileName = "")
        {
            Bitmap      backgroundBmp = null;
            Bitmap      mergedBMP     = null;
            VideoStream aviStream     = default(VideoStream);
            CDGFile     myCDGFile     = new CDGFile(cdgFileName);

            myCDGFile.renderAtPosition(0);
            Bitmap bitmap__1 = (Bitmap)myCDGFile.RGBImage;

            if (!string.IsNullOrEmpty(backgroundFileName))
            {
                try
                {
                    if (IsMovie(backgroundFileName))
                    {
                        backgroundBmp = MovieFrameExtractor.GetBitmap(0, backgroundFileName, CDGFile.CDG_FULL_WIDTH, CDGFile.CDG_FULL_HEIGHT);
                    }
                    if (IsGraphic(backgroundFileName))
                    {
                        backgroundBmp = CDGNet.GraphicUtil.GetCDGSizeBitmap(backgroundFileName);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }
            AviManager aviManager = new AviManager(aviFileName, false);

            if (backgroundBmp != null)
            {
                mergedBMP = GraphicUtil.MergeImagesWithTransparency(backgroundBmp, bitmap__1);
                aviStream = aviManager.AddVideoStream(true, frameRate, mergedBMP);
                mergedBMP.Dispose();
                if (IsMovie(backgroundFileName))
                {
                    backgroundBmp.Dispose();
                }
            }
            else
            {
                aviStream = aviManager.AddVideoStream(true, frameRate, bitmap__1);
            }

            int    count         = 0;
            double frameInterval = 1000 / frameRate;
            long   totalDuration = myCDGFile.getTotalDuration();
            double position      = 0;

            while (position <= totalDuration)
            {
                count   += 1;
                position = count * frameInterval;
                myCDGFile.renderAtPosition(Convert.ToInt64(position));
                bitmap__1 = (Bitmap)myCDGFile.RGBImage;
                if (!string.IsNullOrEmpty(backgroundFileName))
                {
                    if (IsMovie(backgroundFileName))
                    {
                        backgroundBmp = MovieFrameExtractor.GetBitmap(position / 1000, backgroundFileName, CDGFile.CDG_FULL_WIDTH, CDGFile.CDG_FULL_HEIGHT);
                    }
                }
                if (backgroundBmp != null)
                {
                    mergedBMP = GraphicUtil.MergeImagesWithTransparency(backgroundBmp, bitmap__1);
                    aviStream.AddFrame(mergedBMP);
                    mergedBMP.Dispose();
                    if (IsMovie(backgroundFileName))
                    {
                        backgroundBmp.Dispose();
                    }
                }
                else
                {
                    aviStream.AddFrame(bitmap__1);
                }
                bitmap__1.Dispose();
                double percentageDone = (position / totalDuration) * 100;

                if (Status != null)
                {
                    Status(percentageDone.ToString());
                }
                Application.DoEvents();
            }
            myCDGFile.Dispose();
            aviManager.Close();
            if (backgroundBmp != null)
            {
                backgroundBmp.Dispose();
            }

            // Add MP3 to AVI
            Console.Write("|nAVI terminated, add MP3 to AVI");
            AddMP3toAVI(aviFileName, mp3FileName);
        }
示例#7
0
        private void Play()
        {
            try
            {
                if ((mMP3Stream != 0) && Bass.BASS_ChannelIsActive(mMP3Stream) == BASSActive.BASS_ACTIVE_PLAYING)
                {
                    StopPlayback();
                }

                PreProcessFiles();
                if (mCDGFileName == null || mMP3FileName == null)
                {
                    MessageBox.Show("Cannot find a CDG and MP3 file to play together.");
                    StopPlayback();
                    return;
                }

                mPaused     = false;
                mStop       = false;
                mFrameCount = 0;
                mCDGFile    = new CDGFile(mCDGFileName);

                cdgpos = 0;
                long cdgLength = mCDGFile.getTotalDuration();

                // Display progress
                startProgress(cdgLength);

                // Show frmCDGWindow ici
                PlayMP3Bass(mMP3FileName);

                DateTime startTime             = DateTime.Now;
                DateTime endTime               = startTime.AddMilliseconds(cdgLength);
                long     millisecondsRemaining = cdgLength;

                while (millisecondsRemaining > 0)
                {
                    if (mStop)
                    {
                        break;
                    }
                    millisecondsRemaining = (long)endTime.Subtract(DateTime.Now).TotalMilliseconds;
                    cdgpos = cdgLength - millisecondsRemaining;

                    while (mPaused)
                    {
                        endTime = DateTime.Now.AddMilliseconds(millisecondsRemaining);
                        Application.DoEvents();
                    }
                    mCDGFile.renderAtPosition(cdgpos);
                    mFrameCount += 1;
                    mCDGWindow.PictureBox1.Image = mCDGFile.RGBImage;

                    Bitmap mbmp = new Bitmap(mCDGFile.RGBImage);
                    mCDGWindow.PictureBox1.BackColor = mbmp.GetPixel(1, 1);

                    mCDGWindow.PictureBox1.Refresh();

                    // TODO
                    //float myFrameRate = (float)Math.Round(mFrameCount / (pos / 1000), 1);
                    Application.DoEvents();
                }
                StopPlayback();
            }
            catch (Exception ex)
            {
                Console.Write("\n" + ex.Message);
            }
        }