示例#1
0
        /// <summary>
        /// 加载音频文件
        /// </summary>
        /// <param name="filePath">路径</param>
        /// <returns></returns>
        public bool LoadSound(string filePath)
        {
            Stream_playmusic = Bass.BASS_StreamCreateFile(filePath, 0, 0, BASSFlag.BASS_MUSIC_FLOAT);
            string[] soundinfo = Bass.BASS_ChannelGetTagsID3V2(Stream_playmusic);

            return(true);
        }
示例#2
0
        public string getArtist()
        {
            String artist = null;

            artist = Bass.BASS_ChannelGetTagsID3V2(_channel)[1];
            artist = artist.Remove(0, 5);
            return(artist);
        }
示例#3
0
        public string getTitle()
        {
            String title = null;

            title = Bass.BASS_ChannelGetTagsID3V2(_channel)[0];
            title = title.Remove(0, 5);
            return(title);
        }
示例#4
0
        /// <summary>
        /// 获取制定音乐文件的ID3信息
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns>音乐ID3信息</returns>
        public static MusicID3?getInformation(string filePath)
        {
            //打开文件
            int s = Bass.BASS_StreamCreateFile(filePath, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);

            if (0 == s)
            {
                return(null);
            }
            //获取ID3信息
            MusicID3 i = new MusicID3();

            string[] info = Bass.BASS_ChannelGetTagsID3V2(s);
            if (info != null)
            {
                foreach (string str in info)
                {
                    if (str.StartsWith("TTT2", true, null))
                    {
                        i.title = str.Remove(0, 5);
                    }
                    else if (str.StartsWith("TPE1", true, null))
                    {
                        i.artist = str.Remove(0, 5);
                    }
                    else if (str.StartsWith("TALB", true, null))
                    {
                        i.album = str.Remove(0, 5);
                    }
                }
            }
            info = Bass.BASS_ChannelGetTagsID3V1(s);
            if (info != null)
            {
                i.title    = info[0] != "" ? info[0] : i.title;
                i.artist   = info[1] != "" ? info[1] : i.artist;
                i.album    = info[2] != "" ? info[2] : i.album;
                i.year     = info[3];
                i.comment  = info[4];
                i.genre_id = info[5];
                i.track    = info[6];
            }
            //获取时长信息
            double seconds = Bass.BASS_ChannelBytes2Seconds(s, Bass.BASS_ChannelGetLength(s));

            i.duration = Helper.Seconds2Time(seconds);
            //释放文件
            Bass.BASS_StreamFree(s);
            return(i);
        }
示例#5
0
        public int YPrepare(String yurl)
        {
            if (this.y != 20020604)
            {
                Bass.BASS_StreamFree(this.y);
            }
            this.y = Bass.BASS_StreamCreateURL(yurl, 0, BASSFlag.BASS_SAMPLE_FLOAT, null, IntPtr.Zero);

            getYConsole().sendYMessage(String.Join(Environment.NewLine, Bass.BASS_ChannelGetTagsID3V2(this.y)));


            ywave.Show();

            DispatcherTimer yyyy = new DispatcherTimer();

            yyyy.Interval = new TimeSpan(604);
            yyyy.Tick    += (ysender, yevent) => {
                if (true)
                {
                    //ywave.FFT = music.GetFFTData();
                    fft = this.GetFFTData();
                    float[] temp = new float[45];
                    for (int i = 0; i < 45; i++)
                    {
                        temp[i] = fft[i * 2];
                    }
                    ywave.FFT = temp;
                    //layeredTrackBar1.Value = music.Schedule;
                    ywave.NewTime = this.GetFormatTime();
                }
                else
                {
                    ywave.FFT     = null;
                    ywave.Title   = "听音乐";
                    ywave.Artist  = "心灵之音";
                    ywave.NewTime = "00:00";
                    ywave.EndTime = "00:00";
                }
            };
            yyyy.Start();

            return(this.y);
        }
示例#6
0
        /// <summary>
        /// 利用Bass库根据传入的音乐句柄返回该音乐信息
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        private static MusicID3 GetMusicInfoByBass(int handle)
        {
            MusicID3 musicInfo = new MusicID3();

            if (handle != 0)
            {
                string[] info = Bass.BASS_ChannelGetTagsID3V2(handle);
                if (info != null)
                {
                    foreach (string s in info)
                    {
                        if (s.StartsWith("TIT2", true, null))
                        {
                            musicInfo.Title = s.Remove(0, 5);
                        }
                        else if (s.StartsWith("TPE1", true, null))
                        {
                            musicInfo.Artist = s.Remove(0, 5);
                        }
                        else if (s.StartsWith("TALB", true, null))
                        {
                            musicInfo.Album = s.Remove(0, 5);
                        }
                    }
                }

                info = Bass.BASS_ChannelGetTagsID3V1(handle);
                if (info != null)
                {
                    musicInfo.Title    = info[0] != "" ? info[0] : musicInfo.Title;
                    musicInfo.Artist   = info[1] != "" ? info[1] : musicInfo.Artist;
                    musicInfo.Album    = info[2] != "" ? info[2] : musicInfo.Album;
                    musicInfo.Year     = info[3];
                    musicInfo.Comment  = info[4];
                    musicInfo.Genre_id = info[5];
                    musicInfo.Track    = info[6];
                }
            }
            return(musicInfo);
        }
示例#7
0
        /// <summary>
        /// 使用bass库获得MP3、AIF、AAC音乐信息
        /// </summary>
        /// <param name="path">音乐地址</param>
        /// <param name="type">获得的信息类型</param>
        /// <returns></returns>
        public string GetMP3InfoPlus(string path, GetInfoType type)
        {
            string content = null;
            int    stream  = 0;

            if (type != GetInfoType.FileType)
            {
                try
                {
                    stream = Bass.BASS_StreamCreateFile(path, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
                    string[] tags = Bass.BASS_ChannelGetTagsID3V2(stream);
                    if (tags != null)
                    {
                        switch (type)
                        {
                        case GetInfoType.Title:
                        {
                            foreach (string x in tags)
                            {
                                if (x.Contains("TIT"))
                                {
                                    content = x.Remove(0, 5);
                                    break;
                                }
                                else
                                {
                                    content = null;
                                }
                            }        //标题
                            break;
                        }

                        case GetInfoType.Artist:
                        {
                            foreach (string x in tags)
                            {
                                if (x.Contains("TPE"))
                                {
                                    content = x.Remove(0, 5);
                                    break;
                                }
                                else
                                {
                                    content = null;
                                }
                            }        //艺术家
                            break;
                        }

                        case GetInfoType.Album:
                        {
                            foreach (string x in tags)
                            {
                                if (x.Contains("TALB"))
                                {
                                    content = x.Remove(0, 5);
                                    break;
                                }
                                else
                                {
                                    content = null;
                                }
                            }        //专辑名
                            break;
                        }

                        case GetInfoType.Year:
                        {
                            foreach (string x in tags)
                            {
                                if (x.Contains("TYER"))
                                {
                                    content = x.Remove(0, 5);
                                    break;
                                }
                                else
                                {
                                    content = null;
                                }
                            }        //年代
                            break;
                        }

                        case GetInfoType.Length:
                        {
                            if (Convert.ToInt32(Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream))) != -1)
                            {
                                content = Convert.ToString(Convert.ToInt32(Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream))));                                                                                                           //曲长
                            }
                            else
                            {
                                content = "文件损坏";
                                MessageBox.Show("异常:不支持的格式或文件已损坏。\n错误路径:" + path);
                            }
                            break;
                        }

                        default: break;
                        }
                    }
                }
                catch (System.AccessViolationException)
                {
                    MessageBox.Show("警告!内存溢出!程序将退出");
                    Application.Exit();
                }
            }
            if (type == GetInfoType.FileType)
            {
                content = Path.GetExtension(path);                              //格式
            }
            if (type == GetInfoType.Title && content == null)
            {
                content = Path.GetFileNameWithoutExtension(path);
            }
            return(content);
        }
示例#8
0
        /// <summary>
        /// 使用Bass获得音乐年代
        /// </summary>
        /// <param name="stream">Bass音乐流</param>
        /// <param name="extension">音乐格式(扩展名)</param>
        /// <returns>年代</returns>
        private string Bass_Year(int stream, string extension)
        {
            string content = null;

            switch (extension)
            {
            case ".mp3":
            case ".m4a":
            case ".flac":
            case ".aif":
            case ".aac":
            {
                string[] tags = Bass.BASS_ChannelGetTagsID3V2(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("TYER"))
                        {
                            content = x.Remove(0, 5);
                            break;
                        }
                    }
                }
                break;
            }

            case ".ogg":
            {
                string[] tags = Bass.BASS_ChannelGetTagsOGG(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("DATE"))
                        {
                            content = x.Remove(0, 5);
                            break;
                        }
                        else
                        {
                            content = null;
                        }
                    }
                }
                break;
            }

            case ".ape":
            {
                string[] tags = Bass.BASS_ChannelGetTagsAPE(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("Year"))
                        {
                            content = x.Remove(0, 5);
                            break;
                        }
                    }
                }
                break;
            }
            }
            return(content);
        }
示例#9
0
        /// <summary>
        /// 使用Bass获得音乐专辑名
        /// </summary>
        /// <param name="stream">Bass音乐流</param>
        /// <param name="extension">音乐格式(扩展名)</param>
        /// <returns>专辑名</returns>
        private string Bass_Album(int stream, string extension)
        {
            string content = null;

            switch (extension)
            {
            case ".mp3":
            case ".m4a":
            case ".flac":
            case ".aif":
            case ".aac":
            {
                string[] tags = Bass.BASS_ChannelGetTagsID3V2(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("TALB"))
                        {
                            content = x.Remove(0, 5);
                            break;
                        }
                    }
                }
                break;
            }

            case ".ogg":
            {
                string[] tags = Bass.BASS_ChannelGetTagsOGG(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("ALBUM"))
                        {
                            content = x.Remove(0, 6);
                            break;
                        }
                        else
                        {
                            content = null;
                        }
                    }
                }
                break;
            }

            case ".ape":
            {
                string[] tags = Bass.BASS_ChannelGetTagsAPE(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("Album"))
                        {
                            content = x.Split(new char[] { '=' })[1];
                            break;
                        }
                    }
                }
                break;
            }
            }
            return(content);
        }
示例#10
0
        /// <summary>
        /// 使用Bass获得歌曲艺术家
        /// </summary>
        /// <param name="stream">Bass音乐流</param>
        /// <param name="extension">音乐格式(扩展名)</param>
        /// <returns>艺术家</returns>
        private string Bass_Artist(string Path, int stream, string extension)
        {
            string content = null;

            switch (extension)
            {
            case ".mp3":
            case ".m4a":
            case ".flac":
            case ".aif":
            case ".aac":
            {
                string[] tags  = Bass.BASS_ChannelGetTagsID3V2(stream);
                string[] tags7 = Bass.BASS_ChannelGetTagsID3V1(stream);
                string[] tags8 = Bass.BASS_ChannelGetTagsArrayNullTermAnsi(stream, BASSTag.BASS_TAG_FLAC_CUE);
                string[] tags9 = Bass.BASS_ChannelGetTagsArrayNullTermAnsi(stream, BASSTag.BASS_TAG_FLAC_PICTURE);
                BASS_TAG_FLAC_PICTURE[] tags10 = Bass.BASS_ChannelGetTagsFLACPictures(stream);
                string[] tags2 = Bass.BASS_ChannelGetTagsMETA(stream);
                string[] tags3 = Bass.BASS_ChannelGetTagsBWF(stream);
                string[] tags4 = Bass.BASS_ChannelGetTagsICY(stream);
                string[] tags5 = Bass.BASS_ChannelGetTagsMF(stream);
                string[] tags6 = Bass.BASS_ChannelGetTagsRIFF(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("TPE"))
                        {
                            content = x.Remove(0, 5);
                            break;
                        }
                    }
                }
                break;
            }

            case ".ogg":
            {
                string[] tags = Bass.BASS_ChannelGetTagsOGG(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("ARTIST"))
                        {
                            content = x.Remove(0, 7);
                            break;
                        }
                        else
                        {
                            content = null;
                        }
                    }
                }
                break;
            }

            case ".ape":
            {
                string[] tags = Bass.BASS_ChannelGetTagsAPE(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("Artist"))
                        {
                            content = x.Split(new char[] { '=' })[1];
                            break;
                        }
                    }
                }
                break;
            }

            case ".dff":
            case ".dsf":
            {
                stream  = Bass.BASS_StreamCreateFile(Path, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
                content = Bass.BASS_ChannelGetTagsDSDArtist(stream);
                break;
            }
            }
            return(content);
        }
示例#11
0
        /// <summary>
        /// 使用Bass获得音乐标题
        /// </summary>
        /// <param name="stream">Bass音乐流</param>
        /// <param name="extension">音乐格式(扩展名)</param>
        /// <returns>标题</returns>
        private string Bass_Title(string Path, int stream, string extension)
        {
            string content = null;

            switch (extension)
            {
            case ".mp3":
            case ".m4a":
            case ".flac":
            case ".aif":
            case ".aac":
            {
                string[] tags = Bass.BASS_ChannelGetTagsID3V2(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("TIT"))
                        {
                            content = x.Remove(0, 5);
                        }
                        break;
                    }
                }
                break;
            }

            case ".ogg":
            {
                string[] tags = Bass.BASS_ChannelGetTagsOGG(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("TITLE"))
                        {
                            content = x.Remove(0, 6);
                            break;
                        }
                        else
                        {
                            content = null;
                        }
                    }
                }
                break;
            }

            case ".ape":
            {
                string[] tags = Bass.BASS_ChannelGetTagsAPE(stream);
                if (tags != null)
                {
                    foreach (string x in tags)
                    {
                        if (x.Contains("Title"))
                        {
                            content = x.Remove(0, 6);
                            break;
                        }
                    }
                }
                break;
            }

            case ".dff":
            case ".dsf":
            {
                stream  = Bass.BASS_StreamCreateFile(Path, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
                content = Bass.BASS_ChannelGetTagsDSDTitle(stream);
                break;
            }
            }

            if (content == null)
            {
                content = System.IO.Path.GetFileNameWithoutExtension(Path);
            }
            return(content);
        }