Example #1
0
        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();
        }
Example #2
0
 /// <summary>
 /// Called when metadata for a url stream is changed
 /// </summary>
 void MetaSync(int handle, int channel, int data, IntPtr user)
 {
     string[] tags = Bass.BASS_ChannelGetTagsMETA(channel);
     foreach (string tag in tags)
     {
         Console.WriteLine(tag);
     }
 }
Example #3
0
        public bool isUpdateMetadata()
        {
            bool result = false;

            string[] meta = Bass.BASS_ChannelGetTagsMETA(sound[PlayerController.MainChannel]);

            if ((meta != null && bkmeta == null) ||
                (meta != null && bkmeta != null && !meta[0].Equals(bkmeta[0])))
            {
                result = true;
            }

            bkmeta = meta;

            return(result);
        }
Example #4
0
        private void onMetaReceive(int handle, int channel, int data, IntPtr user)
        {
            string[] tags  = Bass.BASS_ChannelGetTagsMETA(channel);
            Regex    regex = new Regex(@"([^\=]+)\=\'([^\']+)*\'");
            string   name;

            foreach (string tag in tags)
            {
                Match m = regex.Match(tag);
                if (m.Success)
                {
                    TextInfo ti = new CultureInfo("pl-PL", false).TextInfo;
                    name = m.Groups[2].Captures[0].Value.Replace("_", " ");
                    name = ti.ToTitleCase(name);
                    wnd_radio.SetName(name);
                }
            }
        }
Example #5
0
        public string CurrentPlay()
        {
            string[] b = Bass.BASS_ChannelGetTagsMETA(channel);
            if (b == null)
            {
                return("Unknown :( (null)");
            }
            int sep = b[0].IndexOf(";");

            if (sep == 0)
            {
                return("Unknown :( (no seperator)");
            }
            string title = b[0].Substring(0, sep);

            title = title.Substring(title.IndexOf("=") + 1).Replace("'", "");
            if (title == "")
            {
                return("Unknown :( (no title)");
            }
            return(title);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
            }
        }
Example #8
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);
        }
Example #9
0
        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