예제 #1
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;
        }
예제 #2
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();
            }
        }