예제 #1
0
        /*
         * Liest alle vorhandenen Informationen von der CD.
         * Liefert FALSE zurück, wenn mindestens ein Lied der CD kein AUDIO-Track ist.
         */

        bool ReadInformation()
        {
            numberOfTracks     = GetNumberOfTracks();
            cdInfo.TotalLength = GetTotalLength();

            if (cdInfo.TotalLength == 0 || numberOfTracks == 0)
            {
                return(false);
            }

            CDInfo.Tracks.Clear();

            cdInfo.TotalLength = 0;

            for (int i = 0; i < numberOfTracks; i++)
            {
                int startTime = GetTrackPosition(i);

                CDInfoTrack newItem = new CDInfoTrack();
                newItem.StartTime = startTime;

                // Die Funktion MCI_STATUS_LENGTH liefert manchmal eine Millisekunde zuviel zurück
                // (vermutlich rundungsprobleme). Deshalb berechnen wir uns die Länge der Tracks
                // selbst (außer beim letzten Track, da geht es nicht anders).
                if (i == numberOfTracks - 1)
                {
                    newItem.Length = GetTrackLength(i);
                }
                else
                {
                    int startTimeNext;
                    startTimeNext  = GetTrackPosition(i + 1);
                    newItem.Length = startTimeNext - startTime;
                }

                newItem.TrackType = GetTrackType(i);

                cdInfo.TotalLength += newItem.Length;

                CDInfo.Tracks.Add(newItem);
            }

            cdInfo.Identity = GetIdentity();

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Die Informationen (TOC) einer CD auslesen
        /// </summary>
        public CDInfo ReadCDInformation(char driveLetter)
        {
            if (Settings.Current.UseMCI)
            {
                return(ReadCDInformationMCI(driveLetter));
            }

            CDInfo mciCDInfo = ReadCDInformationMCI(driveLetter);

            if (mciCDInfo.Tracks.Any(x => x.TrackType != TrackType.Audio))  // Bei einer Daten-CD nehmen wir MCI
            {
                return(mciCDInfo);
            }

            string drive = string.Format("{0}:", driveLetter);

            FMOD.Sound cdSound = null;

            FMOD.RESULT result = system.createStream(drive, FMOD.MODE.OPENONLY, ref cdSound);
            if (result != FMOD.RESULT.OK || cdSound == null)
            {
                return(mciCDInfo);
            }

            int numberOfTracks = 0;

            cdSound.getNumSubSounds(ref numberOfTracks);

            FMOD.CDTOC cdToc = new FMOD.CDTOC();

            int numtags        = 0;
            int numtagsupdated = 0;

            cdSound.getNumTags(ref numtags, ref numtagsupdated);

            for (int i = 0; i < numtags; i++)
            {
                FMOD.TAG tag = new FMOD.TAG();
                if (cdSound.getTag(null, i, ref tag) != FMOD.RESULT.OK)
                {
                    break;
                }
                if (tag.datatype == FMOD.TAGDATATYPE.CDTOC)
                {
                    cdToc = (FMOD.CDTOC)Marshal.PtrToStructure(tag.data, typeof(FMOD.CDTOC));
                    break;
                }
            }

            CDInfo cdInfo = new CDInfo();

            int trackNr = 0;

            for (; trackNr < numberOfTracks; trackNr++)
            {
                CDInfoTrack track = new CDInfoTrack();

                track.StartTime = (((cdToc.min[trackNr] * 60 + cdToc.sec[trackNr]) * 75 + cdToc.frame[trackNr]) * 1000 + 74) / 75;

                if (trackNr > 0)
                {
                    cdInfo.Tracks[trackNr - 1].Length = track.StartTime - cdInfo.Tracks[trackNr - 1].StartTime;
                }
                track.TrackType = TrackType.Audio;
                cdInfo.Tracks.Add(track);
            }

            cdInfo.TotalLength = (((cdToc.min[numberOfTracks] * 60 + cdToc.sec[numberOfTracks]) * 75 + cdToc.frame[numberOfTracks]) * 1000 + 74) / 75;
            cdInfo.Tracks[trackNr - 1].Length = cdInfo.TotalLength - cdInfo.Tracks[trackNr - 1].StartTime;

            cdSound.release();

            /*StringBuilder volumeName = new StringBuilder(1000);
             * StringBuilder fileSystemNameBuffer = new StringBuilder(1000);
             * uint serialNumber = 0;
             * uint maximumComponentLength = 0;
             * uint fileSystemFlags = 0;
             * GetVolumeInformation(drive, volumeName, 1000, ref serialNumber, ref maximumComponentLength, ref fileSystemFlags, fileSystemNameBuffer, 1000);
             *
             * cdInfo.Identity = serialNumber.ToString();*/

            cdInfo.Identity = mciCDInfo.Identity;

            return(cdInfo);
        }