/// <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);
                    }
                }
            }
        }
Exemple #2
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();
        }
Exemple #3
0
        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);
        }
Exemple #5
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);
            }
        }