MP3Import.GetTrackInfo C# (CSharp) Method

GetTrackInfo() public method

public GetTrackInfo ( string path ) : TrackInfo,
path string
return TrackInfo,
    public TrackInfo GetTrackInfo(string path)
    {
        MPGImport.mpg123_init();
        handle_mpg = MPGImport.mpg123_new(null, errPtr);
        x = MPGImport.mpg123_open(handle_mpg, path);
        MPGImport.mpg123_getformat(handle_mpg, out rate, out channels, out encoding);
        intRate = rate.ToInt32();
        intChannels = channels.ToInt32();
        intEncoding = encoding.ToInt32();

        MPGImport.mpg123_id3(handle_mpg, out id3v1, out id3v2);
        MPGImport.mpg123_format_none(handle_mpg);
        MPGImport.mpg123_format(handle_mpg, intRate, intChannels, 208);

        if (id3v1 != IntPtr.Zero)
        {
            MPGImport.mpg123_id3v1 v1 = (MPGImport.mpg123_id3v1)Marshal.PtrToStructure(id3v1, typeof(MPGImport.mpg123_id3v1));
            return new TrackInfo
            {
                Album = new String(v1.album),	    // "Runnin' Wild"
                Artist = new String(v1.artist),	    // "Airbourne"
                Title = new String(v1.title),	    // "Stand Up For Rock N Roll"
                Year = new String(v1.year), 	    // "2007"
                Genre = (v1.genre < GenreText.Length ? GenreText[v1.genre] : string.Empty), // "Rock"
                Comment = new String(v1.comment),    // "Comment"
                Tag = new String(v1.tag),    // "Comment"
                Rate = intRate,
                Channels = intChannels,
                Encoding = intEncoding
            };
        }
        MPGImport.mpg123_close(handle_mpg);

        // TODO: ID3v2 support is more complex.
        return new TrackInfo();
    }

Usage Example

Ejemplo n.º 1
0
        public void AudioDBFileGui(AudioLoader.AudioFileInfo audioFile)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("   " + audioFile.Name);
            GUILayout.FlexibleSpace();
            //string buttonText = " ► ";
            //if (DbPlayer.clip != null && DbPlayer.clip.name == clipName)
            //{
            //if (DbPlayer.isPlaying)
            //buttonText = "  ■  ";
            //else if (DbPlayer.clip.loadState == AudioDataLoadState.Loading)
            //buttonText = "...";
            //}

            //if (GUILayout.Button(buttonText))
            //{
            //if (DbPlayer.isPlaying && DbPlayer.clip.name == clipName)
            //DbPlayer.Stop();
            //else
            //{
            //DbPlayer.clip = clip;
            //DbPlayer.Play();
            //}
            //}
            if (!_expandedDbItems.ContainsKey(audioFile.Name))
                _expandedDbItems.Add(audioFile.Name, false);
            if (GUILayout.Button(" ☰  "))
                _expandedDbItems[audioFile.Name] = !_expandedDbItems[audioFile.Name];

            GUILayout.EndHorizontal();

            if (_expandedDbItems[audioFile.Name])
            {
                GUILayout.Label("   Path:\t" + audioFile.Path);
                GUILayout.Label("   File type:\t" + audioFile.FileExtension);
                if (audioFile.FileExtension.ToUpper() == ".MP3")
                {
                    if (Utils.LibMpg123Installed)
                    {
                        MP3Import.TrackInfo trackInfo;
                        LoadedMP3Info.TryGetValue(audioFile.Path, out trackInfo);
                        if (!LoadedMP3Info.ContainsKey(audioFile.Path))
                        {
                            MP3Import importer = new MP3Import();
                            trackInfo = importer.GetTrackInfo(audioFile.Path);
                            LoadedMP3Info.Add(audioFile.Path, trackInfo);
                        }
                        GUILayout.Label("      Title:\t\t" + trackInfo.Title);
                        GUILayout.Label("      Album:\t\t" + trackInfo.Album);
                        GUILayout.Label("      Artist:\t\t" + trackInfo.Artist);
                        GUILayout.Label("      Year:\t\t" + trackInfo.Year);
                        GUILayout.Label("      Genre:\t\t" + trackInfo.Genre);
                        GUILayout.Label("      Comment:\t" + trackInfo.Comment);
                        GUILayout.Label("      Tag:\t\t" + trackInfo.Tag);
                        GUILayout.Label("      Channels:\t" + trackInfo.Channels);
                        GUILayout.Label("      Encoding:\t" + trackInfo.Encoding);
                        GUILayout.Label("      Rate:\t\t" + trackInfo.Rate);
                    }
                    else
                        GUILayout.Label("MP3 support not installed");
                }
                //GUILayout.Label("   Channels:\t" + clip.channels.ToString());
                //GUILayout.Label("   Frequency:\t" + clip.frequency.ToString() + " Hz");
                //TimeSpan clipLength = TimeSpan.FromSeconds(clip.length);
                //GUILayout.Label("   Length:\t\t" + string.Format("{0:D2}:{1:D2}", clipLength.Minutes, clipLength.Seconds));
                //GUILayout.Label("   Load State:\t" + clip.loadState.ToString());
                //GUILayout.Label("   Load Type:\t" + clip.loadType.ToString());
                //GUILayout.Label("   Samples:\t" + clip.samples.ToString());
            }
        }