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(); }
/// <summary> /// Gets the tags from the Internet Stream. /// </summary> /// <param name="stream"></param> private void SetStreamTags(int stream) { string[] tags = Bass.BASS_ChannelGetTagsICY(stream); if (tags != null) { foreach (string item in tags) { if (item.ToLowerInvariant().StartsWith("icy-name:")) { GUIPropertyManager.SetProperty("#Play.Current.Album", item.Substring(9)); } if (item.ToLowerInvariant().StartsWith("icy-genre:")) { GUIPropertyManager.SetProperty("#Play.Current.Genre", item.Substring(10)); } Log.Info("BASS: Connection Information: {0}", item); } } else { tags = Bass.BASS_ChannelGetTagsHTTP(stream); if (tags != null) { foreach (string item in tags) { Log.Info("BASS: Connection Information: {0}", item); } } } }
static TrackViewModel BuildNetTags() { var t = new TrackViewModel(); // get the meta tags (manually - will not work for WMA streams here) string[] icy = Bass.BASS_ChannelGetTagsICY(Player.Instance.Wave.Handle); if (icy == null) { // try http... icy = Bass.BASS_ChannelGetTagsHTTP(Player.Instance.Wave.Handle); } if (icy != null) { t.Title = icy.Where(c => c.Contains("icy-name:")).First().Replace("icy-name:", ""); t.Bitrate = Convert.ToUInt32(icy.Where(c => c.Contains("icy-br:")).First().Replace("icy-br:", "")); } _tagInfo = new TAG_INFO(Player.Instance.Wave.Path); t.Path = Player.Instance.Wave.Path; if (BassTags.BASS_TAG_GetFromURL(Player.Instance.Wave.Handle, _tagInfo)) { // and display what we get t.Album = _tagInfo.album; t.Artist = _tagInfo.artist; if (!String.IsNullOrEmpty(_tagInfo.title)) { t.Title = _tagInfo.title; } t.Genre = _tagInfo.genre; if (t.Bitrate == 0) { t.Bitrate = (uint)_tagInfo.bitrate; } } mySync = new SYNCPROC(MetaSync); Bass.BASS_ChannelSetSync(Player.Instance.Wave.Handle, BASSSync.BASS_SYNC_META, 0, mySync, IntPtr.Zero); return(t); }
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> /// 使用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); }
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