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; } }
/// <summary> /// Считать альбомарт из файла /// если нет данных вернет null /// </summary> /// <param name="path"></param> /// <returns></returns> private Image GetAlbumArt(string path) { Image img = null; if (!path.StartsWith("http")) //если не поток { int _stream = Bass.BASS_StreamCreateFile(path, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN); if (_stream != 0)//если успешно { TAG_INFO tagInfo = new TAG_INFO(path); if (BassTags.BASS_TAG_GetFromFile(_stream, tagInfo)) { img = (Image)tagInfo.PictureGetImage(0); } } Bass.BASS_StreamFree(_stream);//освобождаем поток } else { if (RecordImages.ContainsKey(path)) { img = RecordImages[path]; } } return(img); }
public void Play(string fileName, int vol = 100) { if (_handle != 0) { Stop(); _currentPosition = 0; OnTrackPositionProgressChanged(new TrackPositionProgrressChangedEventHandlerArgs() { PositionSeconds = _currentPosition }); } _handle = Bass.BASS_StreamCreateFile(fileName, 0, 0, BASSFlag.BASS_DEFAULT); if (_handle != 0) { CurrentTrackLength = GetTrackLength(); TAG_INFO tagInfo = BassTags.BASS_TAG_GetFromFile(fileName); OnTrackChanged(new TrackChangedEventHandlerArgs() { TrackLength = CurrentTrackLength, Title = tagInfo.title, Album = tagInfo.album, Artist = tagInfo.artist, Image = tagInfo.PictureCount > 0 ? tagInfo.PictureGetImage(0): null, Year = tagInfo.year }); Bass.BASS_ChannelSetAttribute(_handle, BASSAttribute.BASS_ATTRIB_VOL, vol / 100f); Bass.BASS_ChannelPlay(_handle, false); _timer.Start(); } }
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 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 TagModel(string file) { TAG_INFO tagInfo = new TAG_INFO(); tagInfo = BassTags.BASS_TAG_GetFromFile(file); if (tagInfo == null) { BitRate = 0; } else { BitRate = tagInfo.bitrate; Freg = tagInfo.channelinfo.freq; Channels = ChannelsDist[tagInfo.channelinfo.chans]; Artist = tagInfo.artist; Album = tagInfo.album; if (tagInfo.title == "") { Title = main.GetFileName(file); } else { Title = tagInfo.title; } Year = tagInfo.year; } }
public Tag(string path, bool isRadio) { TAG_INFO tagInfo = null; if (isRadio) { if (CommonInterface.IsValid(path, CommonInterface.URLPattern) && !CommonInterface.IsValid(path, CommonInterface.PathPattern2)) { tagInfo = new TAG_INFO(path); } } else { tagInfo = BassTags.BASS_TAG_GetFromFile(path); } if (tagInfo != null) { bitRate = tagInfo.bitrate; freq = tagInfo.channelinfo.freq; channels = ChannelsDict[tagInfo.channelinfo.chans]; artist = tagInfo.artist; album = tagInfo.album; genre = tagInfo.genre; title = tagInfo.title; year = tagInfo.year; this.path = path; fileName = System.IO.Path.GetFileName(path); image = tagInfo.PictureGetImage(0); error = false; } else { error = true; } }
/// <summary> /// Recode the file /// </summary> /// <param name = "fileName">Initial file</param> /// <param name = "outFileName">Target file</param> /// <param name = "targetSampleRate">Target sample rate</param> public void RecodeTheFile(string fileName, string outFileName, int targetSampleRate) { int stream = Un4seen.Bass.Bass.BASS_StreamCreateFile(fileName, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_SAMPLE_FLOAT); TAG_INFO tags = new TAG_INFO(); BassTags.BASS_TAG_GetFromFile(stream, tags); int mixerStream = BassMix.BASS_Mixer_StreamCreate(targetSampleRate, 1, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_SAMPLE_FLOAT); if (BassMix.BASS_Mixer_StreamAddChannel(mixerStream, stream, BASSFlag.BASS_MIXER_FILTER)) { WaveWriter waveWriter = new WaveWriter(outFileName, mixerStream, true); const int length = 5512 * 10 * 4; float[] buffer = new float[length]; while (true) { int bytesRead = Un4seen.Bass.Bass.BASS_ChannelGetData(mixerStream, buffer, length); if (bytesRead == 0) { break; } waveWriter.Write(buffer, bytesRead); } waveWriter.Close(); } else { throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString()); } }
public void PlayId(string id) { if (SoundInitialized) { DataProvider.currentlyPlayed = id; TagInfo = new TAG_INFO(); BassStream = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, BASSFlag.BASS_STREAM_AUTOFREE, DataProvider.bassStreamingProc, IntPtr.Zero); if (BassStream == 0) { BASSError err = Bass.BASS_ErrorGetCode(); throw new Exception("Cannot create stream: " + err.ToString()); } if (BassTags.BASS_TAG_GetFromFile(BassStream, TagInfo)) { // nop } else { Program.logging.addToLog("Cannot get tags for stream " + BassStream); } BassTimer.Start(); Bass.BASS_ChannelPlay(BassStream, false); } }
public Song(string file) { TAG_INFO tag_inf = new TAG_INFO(); tag_inf = BassTags.BASS_TAG_GetFromFile(file); if (tag_inf.title == "") { Title = MainWindow.GetFileName(file); } else { Title = tag_inf.title; } AlbumName = tag_inf.album; ArtistName = tag_inf.artist; Year = tag_inf.year; Inf = tag_inf.bitrate + "KBps, " + tag_inf.channelinfo.chans; TagLib.File file_TAG = TagLib.File.Create(file); TrackNumber = file_TAG.Tag.Track.ToString(); int minutes = (int)file_TAG.Properties.Duration.TotalMinutes; int seconds = file_TAG.Properties.Duration.Seconds; string sec = seconds.ToString(); if (sec.Length == 1) { sec = "0" + sec; } Lenght = minutes.ToString() + ":" + sec; }
private void ReadInfoFromFile(Song sInfo) { TAG_INFO tagInfo = new TAG_INFO(sInfo.FileUrl); try { tagInfo = BassTags.BASS_TAG_GetFromFile(sInfo.FileUrl); sInfo.Size = string.Format("{0:F}M", new FileInfo(sInfo.FileUrl).Length / Math.Pow(1024, 2)); sInfo.Album = tagInfo.album; sInfo.Artist = tagInfo.artist; sInfo.Title = tagInfo.title; sInfo.PublicDate = tagInfo.year; sInfo.Company = tagInfo.publisher; sInfo.PicUrl = sInfo.Album == "" ? sInfo.FileName : sInfo.Album; sInfo.Duration = TimeSpan.FromSeconds(tagInfo.duration); if (tagInfo.PictureGetImage(0) != null) { SavePicToLocal(tagInfo.PictureGetImage(0), tagInfo.PictureGetType(0), sInfo.PicUrl); } else { SavePicToLocal(sInfo.FileUrl, sInfo.PicUrl); } } catch (Exception ex) { Debug.Write(ex.Message); } }
public static void OutputTags(string file) { var tagInfo = BassTags.BASS_TAG_GetFromFile(file); Console.WriteLine(" album: " + tagInfo.album); Console.WriteLine(" artist: " + tagInfo.artist); Console.WriteLine("bitrate: " + tagInfo.bitrate); Console.WriteLine(""); }
public TrackInfo(string filename) { Tags = BassTags.BASS_TAG_GetFromFile(filename); Duration = Tags.duration.ToString(); if (Tags == null) { throw new ArgumentException("File not valid!"); } }
public TAG_INFO FillInputFileTags(string inputFileText) { m_inputFileTags = BassTags.BASS_TAG_GetFromFile(inputFileText); if (m_outputFiles == null) { var sound = new SoundFile(tag: m_inputFileTags); m_outputFiles = new OutputFiles(sound); } return(m_inputFileTags); }
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); }
/// <summary> /// Initializes a new instance of the <see cref="BassSongInfo"/> class. /// </summary> /// <param name="Path">The file's path to read</param> public BassSongInfo(string Path) : this() { #region Error checking if (!File.Exists(Path)) { throw new FileNotFoundException($"{Path} does not exists.", Path); } #endregion this.tagInfo = BassTags.BASS_TAG_GetFromFile(Path); }
/// <summary> /// Initializes a new instance of the <see cref="BassSongInfo"/> class. /// </summary> /// <param name="ChannelID">The BASS handle of the channel</param> /// <exception cref="ArgumentException">when ChannelID is 0</exception> public BassSongInfo(int ChannelID) : this() { #region Error checking if (ChannelID == 0) { throw new ArgumentException($"{nameof(ChannelID)} cannot be 0."); } #endregion this.tagInfo = new TAG_INFO(); BassTags.BASS_TAG_GetFromFile(ChannelID, this.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)); } } }
public Track(string filename) { Filename = filename; Tags = BassTags.BASS_TAG_GetFromFile(Filename); if (Tags == null) { throw new ArgumentException("File not valid!"); } // we already create a stream handle // might not be the best place here (especially when having a larger playlist), but for the demo this is okay ;) CreateStream(); }
public TagModel(string file) { TAG_INFO tagInfo = new TAG_INFO(); tagInfo = BassTags.BASS_TAG_GetFromFile(file); BitRate = tagInfo.bitrate; Freq = tagInfo.channelinfo.freq; Channels = ChannelsDist[tagInfo.channelinfo.chans]; Artist = tagInfo.artist; Album = tagInfo.album; Title = (tagInfo.title == "") ? Vars.GetFileName(file) : tagInfo.title; Year = (tagInfo.year != "") ? tagInfo.year : DateTime.Now.Year.ToString(); Pictute = (tagInfo.PictureCount > 0) ? tagInfo.PictureGetImage(0) : Properties.Resources.misic; }
/// <summary> ///Теги для аудиофайла /// </summary> /// <param name="file"></param> public TagModel(string file) { TAG_INFO tagInfo = new TAG_INFO(); tagInfo = BassTags.BASS_TAG_GetFromFile(file); Artist = tagInfo.artist; if (tagInfo.title == "") { Title = Vars.GetFileName(file); } else { Title = tagInfo.title; } }
private void buttonPlay_Click(object sender, System.EventArgs e) { this.label1.Text = ""; Bass.BASS_StreamFree(_Stream); this.timerBPM.Stop(); // test PlugIns... // after additional Add-Ons have been loaded, // they will be supported in the standard BASS_StreamCreateFile methods if (_FileName != String.Empty) { // create the stream _Stream = Bass.BASS_StreamCreateFile(_FileName, 0, 0, BASSFlag.BASS_DEFAULT); // update the tags _tagInfo = new TAG_INFO(_FileName); if (BassTags.BASS_TAG_GetFromFile(_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; } // play the stream if (_Stream != 0 && Bass.BASS_ChannelPlay(_Stream, false)) { //playing... BASS_CHANNELINFO info = new BASS_CHANNELINFO(); if (Bass.BASS_ChannelGetInfo(_Stream, info)) { // start the BPMCounter _bpm.Reset(info.freq); this.timerBPM.Start(); // display the channel info.. this.label1.Text = String.Format("Type={0}, Channels={1}, OrigRes={2}", Utils.BASSChannelTypeToString(info.ctype), info.chans, info.origres); } } else { MessageBox.Show(this, "Error: " + Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode())); } } }
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 TagModel(string file) { TAG_INFO tagInfo = new TAG_INFO(); tagInfo = BassTags.BASS_TAG_GetFromFile(file); BitRate = tagInfo.bitrate; Freq = tagInfo.channelinfo.freq; Channels = channels[tagInfo.channelinfo.chans]; Artist = tagInfo.artist; Album = tagInfo.album; if (tagInfo.title == "") { Title = TrackList.GetFileName(file); } else { Title = tagInfo.title; } Year = tagInfo.year; }
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"); } }
public tagModel(string file) { TAG_INFO tagInfo = new TAG_INFO(); tagInfo = BassTags.BASS_TAG_GetFromFile(file); BitRate = tagInfo.bitrate; freq = tagInfo.channelinfo.freq; channels = chanelDict[tagInfo.channelinfo.chans]; artist = tagInfo.artist; album = tagInfo.album; if (tagInfo.title == "") { title = Main.GetFileName(file); } else { title = tagInfo.title; } year = tagInfo.year; }
static public void ParseFilesBass() { if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, null)) { foreach (string s in m_files) { // Console.WriteLine(s); dtStart3 = DateTime.Now; //TagLib.File trackInfo = TagLib.File.Create(s); TAG_INFO tagInfo = BassTags.BASS_TAG_GetFromFile(s); //if (tagInfo != null) //Console.WriteLine(tagInfo.album + " " + tagInfo.artist + " " + tagInfo.year); //Console.WriteLine(trackInfo.Tag.Album + " " + trackInfo.Tag.FirstArtist + " " + trackInfo.Tag.Year); dtFinish3 = DateTime.Now; dtSpan3 = dtFinish3 - dtStart3; string ms = dtSpan3.TotalMilliseconds.ToString(); Console.WriteLine("Bass: " + ms + "ms"); } } }
public TagInfo(string file) { TAG_INFO tag_info = new TAG_INFO(); tag_info = BassTags.BASS_TAG_GetFromFile(file); bitRate = tag_info.bitrate; freq = tag_info.channelinfo.freq; channels = channelDisc[tag_info.channelinfo.chans]; artist = tag_info.artist; album = tag_info.album; if (tag_info.title == "") { title = Vars.GetFileName(file); } else { title = tag_info.title; } years = tag_info.year; }