Beispiel #1
0
        public void Resume()
        {
            if (!_IsEnabled)
            {
                return;
            }

            if (!_IsValidDisc)
            {
                return;
            }

            if (!_WasPlaying)
            {
                return;
            }

            Mci.PlayParams pp;
            pp.dwFrom     = Mci.MCI_MAKE_TMSF(_PlayTrack, 0, 0, 0);
            pp.dwTo       = Mci.MCI_MAKE_TMSF(_PlayTrack + 1, 0, 0, 0);
            pp.dwCallback = _Form.Handle;// (DWORD)mainwindow;
            int ret = Mci.Play(_DeviceID, Mci.MCI_PLAY, Mci.MCI_TO | Mci.MCI_NOTIFY, ref pp);

            if (ret != 0)
            {
                Con.DPrint("CDAudio: MCI_PLAY failed ({0})\n", ret);
            }

            _IsPlaying = (ret == 0);
        }
Beispiel #2
0
        /// <summary>
        /// CDAudio_GetAudioDiskInfo
        /// </summary>
        public void ReloadDiskInfo()
        {
            _IsValidDisc = false;

            Mci.StatusParams sp = default(Mci.StatusParams);
            sp.dwItem = Mci.MCI_STATUS_READY;
            int ret = Mci.Status(_DeviceID, Mci.MCI_STATUS, Mci.MCI_STATUS_ITEM | Mci.MCI_WAIT, ref sp);

            if (ret != 0)
            {
                Con.DPrint("CDAudio: drive ready test - get status failed\n");
                return;
            }
            if (sp.dwReturn == 0)
            {
                Con.DPrint("CDAudio: drive not ready\n");
                return;
            }

            sp.dwItem = Mci.MCI_STATUS_NUMBER_OF_TRACKS;
            ret       = Mci.Status(_DeviceID, Mci.MCI_STATUS, Mci.MCI_STATUS_ITEM | Mci.MCI_WAIT, ref sp);
            if (ret != 0)
            {
                Con.DPrint("CDAudio: get tracks - status failed\n");
                return;
            }
            if (sp.dwReturn < 1)
            {
                Con.DPrint("CDAudio: no music tracks\n");
                return;
            }

            _IsValidDisc = true;
            _MaxTrack    = (byte)sp.dwReturn;
        }
Beispiel #3
0
        public void Edject()
        {
            int ret = Mci.SendCommand(_DeviceID, Mci.MCI_SET, Mci.MCI_SET_DOOR_OPEN, IntPtr.Zero);

            if (ret != 0)
            {
                Con.DPrint("MCI_SET_DOOR_OPEN failed ({0})\n", ret);
            }
        }
Beispiel #4
0
        public void CloseDoor()
        {
            int ret = Mci.SendCommand(_DeviceID, Mci.MCI_SET, Mci.MCI_SET_DOOR_CLOSED, IntPtr.Zero);

            if (ret != 0)
            {
                Con.DPrint("MCI_SET_DOOR_CLOSED failed ({0})\n", ret);
            }
        }
Beispiel #5
0
        public void Shutdown()
        {
            if (_Form != null)
            {
                _Form.Dispose();
                _Form = null;
            }

            if (!_IsInitialized)
            {
                return;
            }

            Stop();

            if (Mci.SendCommand(_DeviceID, Mci.MCI_CLOSE, Mci.MCI_WAIT, IntPtr.Zero) != 0)
            {
                Con.DPrint("CDAudio_Shutdown: MCI_CLOSE failed\n");
            }
        }
Beispiel #6
0
        public void Stop()
        {
            if (!_IsEnabled)
            {
                return;
            }

            if (!_IsPlaying)
            {
                return;
            }

            int ret = Mci.SendCommand(_DeviceID, Mci.MCI_STOP, 0, IntPtr.Zero);

            if (ret != 0)
            {
                Con.DPrint("MCI_STOP failed ({0})", ret);
            }

            _WasPlaying = false;
            _IsPlaying  = false;
        }
Beispiel #7
0
        public void Init()
        {
            Mci.OpenParams parms = default(Mci.OpenParams);
            parms.lpstrDeviceType = "cdaudio";
            int ret = Mci.Open(IntPtr.Zero, Mci.MCI_OPEN, Mci.MCI_OPEN_TYPE | Mci.MCI_OPEN_SHAREABLE, ref parms);

            if (ret != 0)
            {
                Con.Print("CDAudio_Init: MCI_OPEN failed ({0})\n", ret);
                return;
            }
            _DeviceID = parms.wDeviceID;

            // Set the time format to track/minute/second/frame (TMSF).
            Mci.SetParams sp = default(Mci.SetParams);
            sp.dwTimeFormat = Mci.MCI_FORMAT_TMSF;
            ret             = Mci.Set(_DeviceID, Mci.MCI_SET, Mci.MCI_SET_TIME_FORMAT, ref sp);
            if (ret != 0)
            {
                Con.Print("MCI_SET_TIME_FORMAT failed ({0})\n", ret);
                Mci.SendCommand(_DeviceID, Mci.MCI_CLOSE, 0, IntPtr.Zero);
                return;
            }

            for (byte n = 0; n < 100; n++)
            {
                _Remap[n] = n;
            }

            _IsInitialized = true;
            _IsEnabled     = true;

            ReloadDiskInfo();
            if (!_IsValidDisc)
            {
                Con.Print("CDAudio_Init: No CD in player.\n");
            }
        }
Beispiel #8
0
        public void Pause()
        {
            if (!_IsEnabled)
            {
                return;
            }

            if (!_IsPlaying)
            {
                return;
            }

            Mci.GenericParams gp = default(Mci.GenericParams);
            int ret = Mci.SendCommand(_DeviceID, Mci.MCI_PAUSE, 0, ref gp);

            if (ret != 0)
            {
                Con.DPrint("MCI_PAUSE failed ({0})", ret);
            }

            _WasPlaying = _IsPlaying;
            _IsPlaying  = false;
        }
Beispiel #9
0
        public void Play(byte track, bool looping)
        {
            if (!_IsEnabled)
            {
                return;
            }

            if (!_IsValidDisc)
            {
                ReloadDiskInfo();
                if (!_IsValidDisc)
                {
                    return;
                }
            }

            track = _Remap[track];

            if (track < 1 || track > _MaxTrack)
            {
                Con.DPrint("CDAudio: Bad track number {0}.\n", track);
                return;
            }

            // don't try to play a non-audio track
            Mci.StatusParams sp = default(Mci.StatusParams);
            sp.dwItem  = Mci.MCI_CDA_STATUS_TYPE_TRACK;
            sp.dwTrack = track;
            int ret = Mci.Status(_DeviceID, Mci.MCI_STATUS, Mci.MCI_STATUS_ITEM | Mci.MCI_TRACK | Mci.MCI_WAIT, ref sp);

            if (ret != 0)
            {
                Con.DPrint("MCI_STATUS failed ({0})\n", ret);
                return;
            }
            if (sp.dwReturn != Mci.MCI_CDA_TRACK_AUDIO)
            {
                Con.Print("CDAudio: track {0} is not audio\n", track);
                return;
            }

            // get the length of the track to be played
            sp.dwItem  = Mci.MCI_STATUS_LENGTH;
            sp.dwTrack = track;
            ret        = Mci.Status(_DeviceID, Mci.MCI_STATUS, Mci.MCI_STATUS_ITEM | Mci.MCI_TRACK | Mci.MCI_WAIT, ref sp);
            if (ret != 0)
            {
                Con.DPrint("MCI_STATUS failed ({0})\n", ret);
                return;
            }

            if (_IsPlaying)
            {
                if (_PlayTrack == track)
                {
                    return;
                }
                Stop();
            }

            Mci.PlayParams pp;
            pp.dwFrom     = Mci.MCI_MAKE_TMSF(track, 0, 0, 0);
            pp.dwTo       = (sp.dwReturn << 8) | track;
            pp.dwCallback = _Form.Handle;
            ret           = Mci.Play(_DeviceID, Mci.MCI_PLAY, Mci.MCI_NOTIFY | Mci.MCI_FROM | Mci.MCI_TO, ref pp);
            if (ret != 0)
            {
                Con.DPrint("CDAudio: MCI_PLAY failed ({0})\n", ret);
                return;
            }

            _IsLooping = looping;
            _PlayTrack = track;
            _IsPlaying = true;

            if (_Volume == 0)
            {
                Pause();
            }
        }