private void readStreamTags() { // get the meta tags (manually - will not work for WMA streams here) string[] icy = Bass.BASS_ChannelGetTagsICY(streamRef); if (icy == null) { // try http... icy = Bass.BASS_ChannelGetTagsHTTP(streamRef); } if (icy != null && readTags(icy)) { return; } // get the initial meta data (streamed title...) icy = Bass.BASS_ChannelGetTagsMETA(streamRef); if (icy != null && readTags(icy)) { return; } // an ogg stream meta can be obtained here icy = Bass.BASS_ChannelGetTagsOGG(streamRef); if (icy != null && readTags(icy)) { return; } getTagsFromURL(); }
private bool GetOGGTags(int stream) { tags = Bass.BASS_ChannelGetTagsOGG(stream); if (tags != null) { for (int i = 0; i < tags.Length; i++) { frameId = tags[i].Split('=')[0]; value = tags[i].Split('=')[1]; switch (frameId) { case "Title": title = value; break; case "Artist": artist = value; break; case "Album": album = value; break; case "Comment": comment = value; break; case "Year": year = value; break; case "Genre": genre = value; break; } } return(true); } return(false); }
public void LoadFile(string file) { ChannelType = CHANNEL_TYPE.STREAM; this.Stop(); int stream = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE); if (stream == Bass.FALSE) { stream = Bass.BASS_MusicLoad(file, 0L, 0, BASSFlag.BASS_MUSIC_DECODE | BASSFlag.BASS_MUSIC_FLOAT | BASSFlag.BASS_MUSIC_PRESCAN | BASSFlag.BASS_MUSIC_POSRESETEX | BASSFlag.BASS_MUSIC_RAMP, 0); if (stream != Bass.FALSE) { ChannelType = CHANNEL_TYPE.MUSIC; } } if (stream == Bass.FALSE) { stream = Bass.BASS_StreamCreateURL(file, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_STATUS, downloadProc, IntPtr.Zero); if (stream != Bass.FALSE) { ChannelType = CHANNEL_TYPE.REMOTE_URL; } } TAG_INFO tagInfo = new TAG_INFO(file); BASS_CHANNELINFO channelInfo = stream != Bass.FALSE ? Bass.BASS_ChannelGetInfo(stream) : new BASS_CHANNELINFO(); this.Stream = stream; if (stream != Bass.FALSE) { bool isTagAvailable = ChannelType == CHANNEL_TYPE.REMOTE_URL ? BassTags.BASS_TAG_GetFromURL(stream, tagInfo) : BassTags.BASS_TAG_GetFromFile(stream, tagInfo); this.LengthInBytes = Bass.BASS_ChannelGetLength(stream); this.LengthInSeconds = Bass.BASS_ChannelBytes2Seconds(stream, this.LengthInBytes); } this.TagInfo = tagInfo; this.ChannelInfo = channelInfo; if (ChannelType == CHANNEL_TYPE.REMOTE_URL) { BASSTag tagType = TagInfo.tagType; BASSSync syncFlag = syncFlag = BASSSync.BASS_SYNC_META; if (tagType == BASSTag.BASS_TAG_WMA) { syncFlag = BASSSync.BASS_SYNC_WMA_META; } bool isWMA = false; if (channelInfo.ctype == BASSChannelType.BASS_CTYPE_STREAM_WMA) { isWMA = true; } // ok, do some pre-buffering... System.Diagnostics.Debug.WriteLine("Buffering..."); if (!isWMA) { // display buffering for MP3, OGG... while (true) { long len = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END); if (len == -1) { break; // typical for WMA streams } // percentage of buffer filled float progress = ( Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) - Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT) ) * 100f / len; if (progress > 75f) { break; // over 75% full, enough } System.Diagnostics.Debug.WriteLine(String.Format("Buffering... {0}%", progress)); } } else { // display buffering for WMA... while (true) { long len = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_WMA_BUFFER); if (len == -1L) { break; } // percentage of buffer filled if (len > 75L) { break; // over 75% full, enough } System.Diagnostics.Debug.WriteLine(String.Format("Buffering... {0}%", len)); } } // get the meta tags (manually - will not work for WMA streams here) string[] icy = Bass.BASS_ChannelGetTagsICY(stream); if (icy == null) { // try http... icy = Bass.BASS_ChannelGetTagsHTTP(stream); } if (icy != null) { foreach (string tag in icy) { System.Diagnostics.Debug.WriteLine("ICY: " + tag); } } // get the initial meta data (streamed title...) icy = Bass.BASS_ChannelGetTagsMETA(stream); if (icy != null) { foreach (string tag in icy) { System.Diagnostics.Debug.WriteLine("Meta: " + tag); } } else { // an ogg stream meta can be obtained here icy = Bass.BASS_ChannelGetTagsOGG(stream); if (icy != null) { foreach (string tag in icy) { System.Diagnostics.Debug.WriteLine("Meta: " + tag); } } } syncMetaUpdated = new SYNCPROC(SyncMetaCallback); mySyncHandleMetaUpdate = Bass.BASS_ChannelSetSync(stream, syncFlag, 0, syncMetaUpdated, IntPtr.Zero); } OnStreamCreated(stream); }
private void button1_Click(object sender, System.EventArgs e) { Bass.BASS_StreamFree(_Stream); this.textBox1.Text = ""; _url = this.comboBoxURL.Text; // test BASS_StreamCreateURL bool isWMA = false; if (_url != String.Empty) { this.textBox1.Text += "URL: " + _url + Environment.NewLine; // create the stream _Stream = Bass.BASS_StreamCreateURL(_url, 0, BASSFlag.BASS_STREAM_STATUS, myStreamCreateURL, IntPtr.Zero); if (_Stream == 0) { // try WMA streams... _Stream = BassWma.BASS_WMA_StreamCreateFile(_url, 0, 0, BASSFlag.BASS_DEFAULT); if (_Stream != 0) { isWMA = true; } else { // error this.statusBar1.Text = "ERROR..."; return; } } _tagInfo = new TAG_INFO(_url); BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(_Stream); if (info.ctype == BASSChannelType.BASS_CTYPE_STREAM_WMA) { isWMA = true; } // ok, do some pre-buffering... this.statusBar1.Text = "Buffering..."; if (!isWMA) { // display buffering for MP3, OGG... while (true) { long len = Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_END); if (len == -1) { break; // typical for WMA streams } // percentage of buffer filled float progress = ( Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) - Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT) ) * 100f / len; if (progress > 75f) { break; // over 75% full, enough } this.statusBar1.Text = String.Format("Buffering... {0}%", progress); } } else { // display buffering for WMA... while (true) { long len = Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_WMA_BUFFER); if (len == -1L) { break; } // percentage of buffer filled if (len > 75L) { break; // over 75% full, enough } this.statusBar1.Text = String.Format("Buffering... {0}%", len); } } // get the meta tags (manually - will not work for WMA streams here) string[] icy = Bass.BASS_ChannelGetTagsICY(_Stream); if (icy == null) { // try http... icy = Bass.BASS_ChannelGetTagsHTTP(_Stream); } if (icy != null) { foreach (string tag in icy) { this.textBox1.Text += "ICY: " + tag + Environment.NewLine; } } // get the initial meta data (streamed title...) icy = Bass.BASS_ChannelGetTagsMETA(_Stream); if (icy != null) { foreach (string tag in icy) { this.textBox1.Text += "Meta: " + tag + Environment.NewLine; } } else { // an ogg stream meta can be obtained here icy = Bass.BASS_ChannelGetTagsOGG(_Stream); if (icy != null) { foreach (string tag in icy) { this.textBox1.Text += "Meta: " + tag + Environment.NewLine; } } } // alternatively to the above, you might use the TAG_INFO (see BassTags add-on) // This will also work for WMA streams here ;-) if (BassTags.BASS_TAG_GetFromURL(_Stream, _tagInfo)) { // and display what we get this.textBoxAlbum.Text = _tagInfo.album; this.textBoxArtist.Text = _tagInfo.artist; this.textBoxTitle.Text = _tagInfo.title; this.textBoxComment.Text = _tagInfo.comment; this.textBoxGenre.Text = _tagInfo.genre; this.textBoxYear.Text = _tagInfo.year; } // set a sync to get the title updates out of the meta data... mySync = new SYNCPROC(MetaSync); Bass.BASS_ChannelSetSync(_Stream, BASSSync.BASS_SYNC_META, 0, mySync, IntPtr.Zero); Bass.BASS_ChannelSetSync(_Stream, BASSSync.BASS_SYNC_WMA_CHANGE, 0, mySync, IntPtr.Zero); // start recording... int rechandle = 0; if (Bass.BASS_RecordInit(-1)) { _byteswritten = 0; myRecProc = new RECORDPROC(MyRecoring); rechandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, myRecProc, IntPtr.Zero); } this.statusBar1.Text = "Playling..."; // play the stream Bass.BASS_ChannelPlay(_Stream, false); // record the stream Bass.BASS_ChannelPlay(rechandle, false); } }
/// <summary> /// 获得OGG音乐信息 /// </summary> /// <param name="path">音乐地址</param> /// <param name="type">获取音乐信息类型</param> /// <returns></returns> public string GetOGGInfo(string path, GetInfoType type) { int stream = 0; string content = null; if (type != GetInfoType.FileType) { try { stream = Bass.BASS_StreamCreateFile(path, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT); string[] tags = Bass.BASS_ChannelGetTagsOGG(stream); if (tags != null) { switch (type) { case GetInfoType.Title: { foreach (string x in tags) { if (x.Contains("TITLE")) { content = x.Remove(0, 6); break; } else { content = null; } } //标题 break; } case GetInfoType.Artist: { foreach (string x in tags) { if (x.Contains("ARTIST")) { content = x.Remove(0, 7); break; } else { content = null; } } //艺术家 break; } case GetInfoType.Album: { foreach (string x in tags) { if (x.Contains("ALBUM")) { content = x.Remove(0, 6); break; } else { content = null; } } //专辑名 break; } case GetInfoType.Year: { foreach (string x in tags) { if (x.Contains("DATE")) { 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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
public void bufferAndTitle() { //try if (channel != 0) { _tagInfo = new TAG_INFO("http://174.37.16.73:1725"); BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(channel); if (info.ctype == BASSChannelType.BASS_CTYPE_STREAM_WMA) { isWMA = true; } // ok, do some pre-buffering... status = ""; // don't need any default values e.g. 100% if (!isWMA) { // display buffering for MP3, OGG... while (true) { long len = Bass.BASS_StreamGetFilePosition(channel, BASSStreamFilePosition.BASS_FILEPOS_END); if (len == -1) { break; // typical for WMA streams } // percentage of buffer filled float progress = ( Bass.BASS_StreamGetFilePosition(channel, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) - Bass.BASS_StreamGetFilePosition(channel, BASSStreamFilePosition.BASS_FILEPOS_CURRENT) ) * 100f / len; if (progress > 75f) { break; // over 75% full, enough } status = String.Format("{0}%", progress); } } else { // display buffering for WMA... while (true) { long len = Bass.BASS_StreamGetFilePosition(channel, BASSStreamFilePosition.BASS_FILEPOS_WMA_BUFFER); if (len == -1L) { break; } // percentage of buffer filled if (len > 75L) { break; // over 75% full, enough } status = String.Format("{0}%", len); } } // Titles from the Shoutcast player is retrieved here. string[] icy = Bass.BASS_ChannelGetTagsICY(channel); //if (icy == null) //{ // // try http... // icy = Bass.BASS_ChannelGetTagsHTTP(channel); //} //if (icy != null) //{ // foreach (string tag in icy) // { // title += "ICY: " + tag + Environment.NewLine; // } //} // get the initial meta data (streamed title...) icy = Bass.BASS_ChannelGetTagsMETA(channel); if (icy != null) { foreach (string tag in icy) { title = tag; } } else { // an ogg stream meta can be obtained here icy = Bass.BASS_ChannelGetTagsOGG(channel); if (icy != null) { foreach (string tag in icy) { title = tag; } } } } // channel != 0 check end here. else { title = "OFFLINE"; } } // bufferAnd Title