示例#1
0
        /// <summary>
        /// Initializes the cdg library
        /// </summary>
        /// <param name="playlistItem"></param>
        private void InitializeCdgLibrary(PlaylistItem playlistItem)
        {
            IntPtr applicationHandle  = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            IntPtr parentWindowHandle = new WindowInteropHelper(_videoPlayerWindow).Handle;

            string mp3FilePath = playlistItem.Song.FilePath;
            string cdgFilePath = playlistItem.Song.CdgFilePath;

            if (playlistItem.Song.Extension.Equals("zip"))
            {
                _zipFileHelper = new ZipFileHelper();
                Song tmpUnzippedSong = _zipFileHelper.ExtractFileTemporarily(mp3FilePath);
                mp3FilePath = tmpUnzippedSong.FilePath;
                cdgFilePath = tmpUnzippedSong.CdgFilePath;
            }

            _cdgLibDllHandle = CdgLibraryWrapper.CDGPlayerOpenExt(applicationHandle,
                                                                  cdgFilePath,
                                                                  parentWindowHandle,
                                                                  0);

            _videoPlayerWindow.VideoPlayer.Source = new Uri(mp3FilePath);

            _cdgWindowHeight = _videoPlayerWindow.Height;
            _cdgWindowWidth  = _videoPlayerWindow.Width;
            CdgLibraryWrapper.CDGPlayerHeightSet(_cdgLibDllHandle, (int)_cdgWindowHeight);
            CdgLibraryWrapper.CDGPlayerWidthSet(_cdgLibDllHandle, (int)_cdgWindowWidth);
        }
示例#2
0
 /// <summary>
 /// Starts the playback again after it has been paused
 /// </summary>
 public void Unpause()
 {
     if (IsCdgLibraryInitialized())
     {
         CdgLibraryWrapper.CDGPlayerPlay(_cdgLibDllHandle);
         _videoPlayerWindow.VideoPlayer.Play();
     }
 }
示例#3
0
 /// <summary>
 /// Sets the song position inside the played song
 /// </summary>
 /// <param name="newSongPositionInMs">new position in milliSeconds</param>
 public void SetSongPosition(int newSongPositionInMs)
 {
     if (IsPlaying())
     {
         _videoPlayerWindow.VideoPlayer.Position = TimeSpan.FromMilliseconds(newSongPositionInMs);
         int songPosInMs = CdgLibraryWrapper.CDGPlayerPosGet(_cdgLibDllHandle);
         int deltaSecs   = (newSongPositionInMs - songPosInMs) / 1000;
         CdgLibraryWrapper.CDGPlayerSeek(_cdgLibDllHandle, deltaSecs);
     }
 }
示例#4
0
 /// <summary>
 /// timer event to synchronize cdg playback position with mp3 position
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SetCdgPositionTimer_Tick(object sender, EventArgs e)
 {
     try
     {
         if (IsCdgLibraryInitialized())
         {
             double audioPlayerPosition = _videoPlayerWindow.VideoPlayer.Position.TotalMilliseconds;
             CdgLibraryWrapper.CDGPlayerPosSet(_cdgLibDllHandle, (int)audioPlayerPosition);
         }
     }
     catch (Exception)
     {
     }
 }
示例#5
0
 /// <summary>
 /// Stops the playback
 /// </summary>
 public void Stop()
 {
     if (IsCdgLibraryInitialized())
     {
         _setCdgPositionTimer.Stop();
         CdgLibraryWrapper.CDGPlayerHide(_cdgLibDllHandle);
         CdgLibraryWrapper.CDGPlayerClose(_cdgLibDllHandle);
         _cdgLibDllHandle = IntPtr.Zero;
         _videoPlayerWindow.VideoPlayer.Stop();
         if (_zipFileHelper != null)
         {
             _zipFileHelper.Dispose();
             _zipFileHelper = null;
         }
     }
 }
示例#6
0
        /// <summary>
        /// When the cdg player window is resized and the
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="sizeChangedEventArgs"></param>
        private void CDGPlayerWindowOnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
        {
            _cdgWindowHeight = ((Window)sender).Height;
            _cdgWindowWidth  = ((Window)sender).Width;

            if (IsCdgLibraryInitialized())
            {
                if (sizeChangedEventArgs.HeightChanged)
                {
                    CdgLibraryWrapper.CDGPlayerHeightSet(_cdgLibDllHandle, (int)_cdgWindowHeight);
                }
                else
                {
                    CdgLibraryWrapper.CDGPlayerWidthSet(_cdgLibDllHandle, (int)_cdgWindowWidth);
                }
            }
        }
示例#7
0
        /// <summary>
        /// starts the playback of the given song
        /// </summary>
        /// <param name="song"></param>
        public void Play(PlaylistItem song)
        {
            if (IsCdgLibraryInitialized() == false)
            {
                try
                {
                    InitializeCdgLibrary(song);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("The song " + song.Song.Artist + ":" + song.Song.Title + " could not be played.", "Error");
                    return;
                }
            }

            _videoPlayerWindow.VideoPlayer.LoadedBehavior   = MediaState.Manual;
            _videoPlayerWindow.VideoPlayer.UnloadedBehavior = MediaState.Manual;
            _videoPlayerWindow.VideoPlayer.Play();
            CdgLibraryWrapper.CDGPlayerShow(_cdgLibDllHandle);
            CdgLibraryWrapper.CDGPlayerPlay(_cdgLibDllHandle);
            _setCdgPositionTimer.Start();
        }