public static void GetTagsFromCurrentURLStream(int stream) { TAG_INFO tagInfo = new TAG_INFO(); IntPtr tagsIntPtr = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_META); BassTags.BASS_TAG_GetFromURL(stream, tagInfo); }
public void GetStationInfo() { TAG_INFO tagInfo = new TAG_INFO(URL); if (BassTags.BASS_TAG_GetFromURL(BassNetHelper.Stream, tagInfo)) { if (TrackArtist != tagInfo.artist && TrackName != tagInfo.title) { TrackArtist = tagInfo.artist; TrackName = tagInfo.title; TrackGenre = tagInfo.genre; if (tagInfo.bpm == "") { ChannelInfo = "Bitrate : " + tagInfo.bitrate; } else { ChannelInfo = "Bitrate : " + tagInfo.bitrate + "kBit/sec Bpm : " + tagInfo.bpm; } GetImageLink(SongImageLink); IsSongChanged = true; } else { IsSongChanged = false; } } else { TrackArtist = "No Data"; TrackName = "No Data"; } }
public static void updateTags() { if (BassTags.BASS_TAG_GetFromURL(BassModelLive.audioStreamBass, _tags) && _tags.artist != " ") { try { session = new Session(API_KEY, API_SECRET); crobAlbum = new Album(_tags.artist, _tags.title, session); crobArtist = new Artist(_tags.artist, session); titleArtist.Artist = _tags.artist; titleArtist.Titles = _tags.title; titleArtist.ImgUrl = crobAlbum.GetImageURL(); titleArtist.CustomUrl = crobAlbum.GetURL(0); } catch { try { titleArtist.ImgUrl = crobArtist.GetImageURL(); titleArtist.CustomUrl = crobArtist.GetURL(0); } catch { titleArtist.ImgUrl = ""; } } } else if (_tags != null) { titleArtist.Artist = _tags.album; titleArtist.Titles = _tags.comment; } }
public static TAG_INFO GetMP3Tags() { TAG_INFO tagInfo = new TAG_INFO(); var tag = Bass.BASS_ChannelGetTags(_stream, BASSTag.BASS_TAG_META); if (tag != null) { BassTags.BASS_TAG_GetFromURL(_stream, tagInfo); } return(tagInfo); }
static public PlaylistItem GetTags(string path) { TAG_INFO tagInfo = new TAG_INFO(path); if (!new System.Text.RegularExpressions.Regex("^(ftp|http)").IsMatch(path)) { string extension = new System.IO.FileInfo(path).Extension; if (!MainForm.supportedExts.Contains("*" + extension.ToLower())) { MessageBox.Show("File \"" + path + "\" is an unsupported file type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } int type = PlaylistItem.TYPE_STREAM_FILE; if (Bass.SupportedMusicExtensions.Contains("*" + extension)) { type = PlaylistItem.TYPE_MUSIC; } tagInfo = BassTags.BASS_TAG_GetFromFile(path); if (tagInfo == null) { return(new PlaylistItem("?", "?", "?", "?", path, type)); } else { return(new PlaylistItem(tagInfo.track, tagInfo.title, tagInfo.artist, tagInfo.album, path, type)); } } else { if (MainForm.stream != 0) { bool tagsAvailable = BassTags.BASS_TAG_GetFromURL(MainForm.stream, tagInfo); if (tagsAvailable) { return(new PlaylistItem(tagInfo.track, tagInfo.title, tagInfo.artist, tagInfo.album, path, PlaylistItem.TYPE_STREAM_URL)); } else { return(new PlaylistItem("?", "?", "?", "?", path, PlaylistItem.TYPE_STREAM_URL)); } } else { return(new PlaylistItem("?", "?", "?", "?", path, PlaylistItem.TYPE_STREAM_URL)); } } }
private bool Bass() { Uri URL = new Uri(m_UrlStream); TAG_INFO tags = new TAG_INFO(); Un4seen.Bass.Bass.BASS_StreamFree(numberStream); numberStream = Un4seen.Bass.Bass.BASS_StreamCreateURL(URL.OriginalString, 0, BASSFlag.BASS_STREAM_STATUS, _downloadProc_, IntPtr.Zero); Un4seen.Bass.Bass.BASS_ChannelGetTags(numberStream, BASSTag.BASS_TAG_MUSIC_MESSAGE); BassTags.BASS_TAG_GetFromURL(numberStream, tags); if (m_Singer != tags.artist || m_Song != tags.title) { m_Singer = tags.artist; m_Song = tags.title; return(true); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="BassSongInfo"/> class. /// </summary> /// <param name="Info">A <see cref="RemoteResourceInfo"/> instance that holds informations about the requested URI.</param> public BassSongInfo(RemoteResourceInfo Info) { #region Error checking if (Info == null) { throw new ArgumentNullException(nameof(Info)); } if (!Info.RequestSucceeded) { throw new ArgumentException($"{nameof(Info)} represents a failed request."); } if (Info.IsPlaylist) { throw new ArgumentException($"{nameof(Info)} is a playlist, not a media resource."); } #endregion if (Info.IsInternetRadioStream) { int Channel = Bass.BASS_StreamCreateURL( url: Info.RequestUri.ToString(), offset: 0, flags: BASSFlag.BASS_STREAM_STATUS, proc: null, user: IntPtr.Zero ); if (Channel == 0) { throw new Exception("Could not connect to the radio stream."); } this.tagInfo = new TAG_INFO(); if (!BassTags.BASS_TAG_GetFromURL(Channel, this.tagInfo)) { throw new Exception("Could not retrieve informations about the radio stream."); } } else { this.tagInfo = BassTags.BASS_TAG_GetFromFile(Info.RequestUri.ToString()); } }
public TAG_INFO UpdateTrackTagInfo(TrackVM track) { string path = track.Location; bool ret = false; bool isURL = Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute); int stream = Bass.FALSE; if (isURL == false) { stream = Bass.BASS_StreamCreateFile(path, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO); if (stream == Bass.FALSE) { stream = Bass.BASS_MusicLoad(path, 0L, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_MUSIC_PRESCAN, 0); } } else { stream = Bass.BASS_StreamCreateURL(path, 0, BASSFlag.BASS_STREAM_DECODE, null, IntPtr.Zero); } TAG_INFO tagInfo = new TAG_INFO(path); bool isTagAvailable = false; if (stream != Bass.FALSE) { isTagAvailable = isURL ? BassTags.BASS_TAG_GetFromURL(stream, tagInfo) : BassTags.BASS_TAG_GetFromFile(stream, tagInfo); } double length = Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream)); Bass.BASS_StreamFree(stream); ret = isTagAvailable; OnTrackTagInfoUpdated(track, tagInfo); return(tagInfo);; }
/// <summary> /// Creates a stream for the given track. /// If the stream is created successfully, the track is automatically played. Thus, /// this implementation is synchronous. /// </summary> /// <param name="track">The track to create the stream for and play.</param> protected virtual void CreateStream(IAudioItem track) { int stream = 0; // If we have a webcast, create a stream for one of the available URIs if (track is IWebcast) { var streams = ((IWebcast)track).Streams; foreach (var si in streams) { var url = si.Uri.ToString(); stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_STREAM_STATUS | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT, null, IntPtr.Zero); Log(Bass.BASS_ErrorGetCode().ToString()); if (stream != 0) { Un4seen.Bass.AddOn.Tags.TAG_INFO tagInfo = new TAG_INFO(url); if (BassTags.BASS_TAG_GetFromURL(stream, tagInfo)) { // display the tags... } break; } } } // Else, just load the track else if (track is IFileTrack) { var path = Path.GetFullPath(((ITrack)track).Uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped)); stream = Bass.BASS_StreamCreateFile(path, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN); } // Start the stream if successfull if (stream != 0) { this.StreamCreated(track, stream); } else { throw new NotImplementedException("Unhandled: no valid stream created"); } }
/// <summary> /// Starts tracking metadata changes. /// </summary> /// <param name="cancellationToken">Cancellation handling token.</param> private void StartMetadataHandle(CancellationToken cancellationToken) { Task.Run(() => { while (!cancellationToken.IsCancellationRequested) { BASS_CHANNELINFO channelInfo = Bass.BASS_ChannelGetInfo(handle); Format format = Format.Unknown; if (channelInfo != null) { format = channelInfo.ctype.ToFormat(); } TAG_INFO tagInfo = new TAG_INFO(url); String songName = null; String artist = null; String title = null; Int32 bitrate = 0; if (BassTags.BASS_TAG_GetFromURL(handle, tagInfo)) { songName = tagInfo.ToString(); artist = tagInfo.artist; title = tagInfo.title; bitrate = tagInfo.bitrate; } IMetadata metadata = new Metadata(songName, artist, title, format, bitrate); if (!metadata.Equals(Metadata)) { Metadata = metadata; MetadataChanged?.Invoke(metadata); } Thread.Sleep(250); } }); }
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); }
private void meta_sync(int a, int b, int c, IntPtr d) { System.Diagnostics.Debug.WriteLine("Meta Sync: " + a + " " + b + " " + c + " " + d.ToInt32()); var tgs = new TAG_INFO(); bool result = BassTags.BASS_TAG_GetFromURL(_stream, tgs); if (result) { System.Diagnostics.Debug.WriteLine(tgs.ToString()); } _currentSong = new SongInfo(_currentSong.FileName, tgs.artist, tgs.album, tgs.title, 0, 0, 0, tgs.genre, "", false); _playingStream = true; if (AudioscrobblerEnabled && !string.IsNullOrEmpty(_currentSong.Title) && !string.IsNullOrEmpty(_currentSong.Artist)) { var req = new AudioscrobblerRequest(); req.Username = AudioscrobblerUserName; req.Password = AudioscrobblerPassword; req.SubmitTrack(_currentSong); } OnSongOpened(); }
public void Play(int volume) { Stop(); if (InitBass(HZ)) { Stream = Bass.BASS_StreamCreateURL(URL, 0, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero); tagInfo = new TAG_INFO(URL); if (BassTags.BASS_TAG_GetFromURL(Stream, tagInfo)) { UpdatePlayList(); } mySync = new SYNCPROC(MetaSync); Bass.BASS_ChannelSetSync(Stream, BASSSync.BASS_SYNC_META, 0, mySync, IntPtr.Zero); Bass.BASS_ChannelPlay(Stream, false); //Установка громкости Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, volume / 100f); } }
public void GetStationInfo() { TAG_INFO tagInfo = new TAG_INFO(URL); if (BassTags.BASS_TAG_GetFromURL(BassNetHelper.Stream, tagInfo)) { TrackArtist = tagInfo.artist; TrackName = tagInfo.title; TrackGenre = tagInfo.genre; if (tagInfo.bpm == "") { ChannelInfo = "Bitrate : " + tagInfo.bitrate; } else { ChannelInfo = "Bitrate : " + tagInfo.bitrate + "kBit/sec Bpm : " + tagInfo.bpm; } } else { TrackArtist = "No Data"; TrackName = "No Data"; } }
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); } }
private void getTagsFromURL() { if (BassTags.BASS_TAG_GetFromURL(streamRef, tagInfo)) { int trackNum = 0; Int32.TryParse(tagInfo.track, out trackNum); int year = 0; Int32.TryParse(tagInfo.year, out year); Track t = new Track(0, tagInfo.title + tagInfo.artist, // need something since equals uses filepath Track.FileType.None, tagInfo.title, String.Empty, tagInfo.artist, tagInfo.albumartist, tagInfo.composer, String.Empty, String.Empty, 0, trackNum, 0, year, 0, 0, tagInfo.bitrate, 0, false, DateTime.Now, DateTime.Now, DateTime.Now, tagInfo.encodedby, tagInfo.channelinfo.chans, tagInfo.channelinfo.sample, ChangeType.None, null, float.MinValue, float.MinValue); if (station.Name.Length == 0 && tagInfo.album.Trim().Length > 0) { station.Name = tagInfo.album.Trim(); Radio.StationNameChanged(); } if (station.Name.Length == 0 && tagInfo.title.Trim().Length > 0) { station.Name = tagInfo.title.Trim(); Radio.StationNameChanged(); } if (station.Genre.Length == 0 && tagInfo.genre.Trim().Length > 0) { station.Genre = tagInfo.genre.Trim(); Radio.StationGenreChanged(); } if (tagInfo.bitrate > 0) { station.BitRate = tagInfo.bitrate; } Radio.InvalidateInstance(); controller.RadioTrack = t; controller.Invalidate(); } }
public string get_tags(string nm, ref string bitr) { if (_Stream == 0) { return(""); } try { init_tag(); if (BassTags.BASS_TAG_GetFromURL(_Stream, _tagInfo)) { bitr = _tagInfo.bitrate.ToString(); string artist = StrEncod(_tagInfo.artist); string title = StrEncod(_tagInfo.title); title = title.Replace("- 0:00", ""); string rez = artist + " - " + title; if (artist == "" || artist == " " || artist == ";") { rez = title; } if (title == "" || title == " " || title == ";" || title == "0:00" || title == "0") { rez = artist; } if (artist == "" && title == "") { rez = "no artist"; } if (rez == " ") { rez = "none"; } return(rez); } // 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) // { // tags += "ICY: " + tag + Environment.NewLine; // } //} //// get the initial meta data (streamed title...) //icy = Bass.BASS_ChannelGetTagsMETA(_Stream); //if (icy != null) //{ // foreach (string tag in icy) // { // tags += "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) // { // tags += "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; //} } catch (Exception ex) { System.Windows.MessageBox.Show(ex.ToString()); } return("null"); }
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); }
/// <summary> /// Create the stream for the file assigned to the Musicstream /// </summary> private void CreateStream() { if (!_temporaryStream) { Log.Info("BASS: ---------------------------------------------"); Log.Info("BASS: Creating BASS audio stream"); } BASSFlag streamFlags = BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE; _fileType = Utils.GetFileType(_filePath); switch (_fileType.FileMainType) { case FileMainType.Unknown: return; case FileMainType.AudioFile: case FileMainType.MidiFile: _stream = Bass.BASS_StreamCreateFile(_filePath, 0, 0, streamFlags); if (!_temporaryStream) { // Read the Tag _musicTag = TagReader.TagReader.ReadTag(_filePath); } break; case FileMainType.CDTrack: // StreamCreateFile causes problems with Multisession disks, so use StreamCreate with driveindex and track index int driveindex = Config.CdDriveLetters.IndexOf(_filePath.Substring(0, 1)); int tracknum = Convert.ToInt16(_filePath.Substring(_filePath.IndexOf(".cda") - 2, 2)); _stream = BassCd.BASS_CD_StreamCreate(driveindex, tracknum - 1, streamFlags); break; case FileMainType.MODFile: _stream = Bass.BASS_MusicLoad(_filePath, 0, 0, BASSFlag.BASS_SAMPLE_SOFTWARE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MUSIC_DECODE | BASSFlag.BASS_MUSIC_PRESCAN | BASSFlag.BASS_MUSIC_RAMP, 0); break; case FileMainType.WebStream: // Turn on parsing of ASX files Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PLAYLIST, 2); _stream = Bass.BASS_StreamCreateURL(_filePath, 0, streamFlags, null, IntPtr.Zero); if (_stream != 0 && !_temporaryStream) { // Get the Tags and set the Meta Tag SyncProc _tagInfo = new TAG_INFO(_filePath); SetStreamTags(_stream); if (BassTags.BASS_TAG_GetFromURL(_stream, _tagInfo)) { GetMetaTags(); } Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_META, 0, _metaTagSyncProcDelegate, IntPtr.Zero); Log.Debug("BASS: Webstream found - fetching stream {0}", Convert.ToString(_stream)); } break; } if (_stream == 0) { Log.Error("BASS: Unable to create Stream for {0}. Reason: {1}.", _filePath, Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode())); return; } // When we have a MIDI file, we need to assign the sound banks to the stream if (_fileType.FileMainType == FileMainType.MidiFile && Config.SoundFonts != null) { BassMidi.BASS_MIDI_StreamSetFonts(_stream, Config.SoundFonts, Config.SoundFonts.Length); } _channelInfo = Bass.BASS_ChannelGetInfo(_stream); if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK) { Log.Error("BASS: Unable to get information for stream {0}. Reason: {1}.", _filePath, Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode())); return; } // This stream has just been created to check upfront, the sample rate // We don't need further processing of this stream if (_temporaryStream) { return; } Log.Info("BASS: Stream Information"); Log.Info("BASS: ---------------------------------------------"); Log.Info("BASS: File: {0}", _filePath); Log.Debug("BASS: Type of Stream: {0}", _channelInfo.ctype); Log.Info("BASS: Number of Channels: {0}", _channelInfo.chans); Log.Info("BASS: Stream Samplerate: {0}", _channelInfo.freq); Log.Debug("BASS: Stream Flags: {0}", _channelInfo.flags); Log.Info("BASS: ---------------------------------------------"); Log.Debug("BASS: Registering stream playback events"); RegisterPlaybackEvents(); AttachDspToStream(); if (Config.EnableReplayGain && _musicTag != null) { SetReplayGain(); } Log.Info("BASS: Successfully created BASS audio stream"); Log.Info("BASS: ---------------------------------------------"); }