-
Oct 17th, 2020, 09:00 PM
#1
Thread Starter
Member
[RESOLVED] BASS_ChannelGetTags and BASS_ChannelSetSync
Decided to get away from WMP for my Icecast player and have tried working with Bass.dll and Bass.Net
So far I am able to get the stream to play but no I am having issues trying to read the metadata from the stream.
BASS_ChannelGetTags (to get stream info and titles) and BASS_ChannelSetSync (for title updates)
I honestly have no idea where to go from here.
It states to pull Tags use:
Code:
Dim tags As String() = Bass.BASS_ChannelGetTagsICY(stream)
If tags Is Nothing Then
' try http...
tags = Bass.BASS_ChannelGetTagsHTTP(stream)
End If
If Not (tags Is Nothing) Then
Dim tag As String
For Each tag In tags
(honestly not sure what goes here to show Title and Artist)
Next tag
End If
And this to reload once new song starts playing
Code:
Private _mySync As SYNCPROC
Dim stream As Integer = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, Nothing, 0)
' set a sync to get notified on stream title updates
_mySync = New SYNCPROC(AddressOf MetaSync)
Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero)
Bass.BASS_ChannelPlay(stream, False)
Private Sub MetaSync(ByVal handle As Integer, ByVal channel As Integer,
ByVal data As Integer, ByVal user As IntPtr)
' BASS_SYNC_META is triggered
Dim tags() As String = Bass.BASS_ChannelGetTagsMETA(channel)
Dim tag As String
For Each tag In tags
(honestly not sure what goes here to show Title and Artist)
End Sub
Trying to set to show in labels
title = songtitle.text
artist = songartist.text
-
Oct 17th, 2020, 09:24 PM
#2
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Originally Posted by SkyRanger
It states to pull Tags use:
Code:
Dim tags As String() = Bass.BASS_ChannelGetTagsICY(stream)
If tags Is Nothing Then
' try http...
tags = Bass.BASS_ChannelGetTagsHTTP(stream)
End If
If Not (tags Is Nothing) Then
Dim tag As String
For Each tag In tags
(honestly not sure what goes here to show Title and Artist)
Next tag
End If
What goes there to show title and artist depends on what the contents of that String array is. Did you bother to look? I would guess that each element would contain a label and a value so, in that case, you would obviously need to find the elements with the labels you are interested in and get the corresponding values. How you process data depends on that data so you need to have a clear understanding of the structure of that data. If you want us to help you then you need to provide us with that same clear understanding, i.e. show us the data you're working with.
-
Oct 17th, 2020, 09:34 PM
#3
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Me.playlink = "http://shaincast.caster.fm:37405/listen.mp3?authn1124b16fbd1cfa0fccd03d9d0c68fd32"
VolumeBar.Value = My.Settings.volume * 100
TaskbarAssistant1.Assign(Me)
BassNet.Registration("", "")
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
BassSfx.BASS_SFX_Init(System.Diagnostics.Process.GetCurrentProcess().Handle, Me.Handle)
CommandFile = Command$()
End Sub
Code:
Function PlayPause()
If stream <> 0 Then
If Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING Then
Bass.BASS_ChannelPause(stream)
ThumbnailButton2.Image = My.Resources.Media_Controls_Play_icon
Else
Bass.BASS_ChannelPlay(stream, False)
ThumbnailButton2.Image = My.Resources.Media_Controls_Pause_icon
Timer1.Start()
Timer2.Start()
End If
Else
Try
Timer1.Stop()
Bass.BASS_ChannelStop(stream)
stream = Bass.BASS_StreamCreateURL("http://shaincast.caster.fm:37405/listen.mp3?authn1124b16fbd1cfa0fccd03d9d0c68fd32", 0, BASSFlag.BASS_DEFAULT, Nothing, IntPtr.Zero)
Bass.BASS_ChannelPlay(stream, False)
Timer1.Start()
Catch ex As Exception
MsgBox("Provided Link Could Not Be Played!!")
' Timer1.Start()
End Try
End If
End Function
Reference the Metadata information for the stream unsure at the moment how to implement that in to the code. Been fighting with this for a while now.
-
Oct 17th, 2020, 10:24 PM
#4
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
None of that addresses what I posted. Change this:
vb.net Code:
Dim tags As String() = Bass.BASS_ChannelGetTagsICY(stream)
If tags Is Nothing Then
' try http...
tags = Bass.BASS_ChannelGetTagsHTTP(stream)
End If
If Not (tags Is Nothing) Then
Dim tag As String
For Each tag In tags
(honestly not sure what goes here to show Title and Artist)
Next tag
End If
to this:
vb.net Code:
Dim tags As String() = Bass.BASS_ChannelGetTagsICY(stream)
If tags Is Nothing Then
' try http...
tags = Bass.BASS_ChannelGetTagsHTTP(stream)
End If
If Not (tags Is Nothing) Then
Dim tag As String
For Each tag In tags
Console.WriteLine(tag)
Next tag
End If
and look at the Output window to see what the data actually looks like. Once you know what the data looks like, you can work out how to process it. It's just Strings, like any other. Once you know what the text is then you can decide what elements of the array you care about and how to process them to get that part(s) that you want. If you don't know what the data looks like, why would you know how to process it?
-
Oct 18th, 2020, 02:21 PM
#5
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Originally Posted by jmcilhinney
What goes there to show title and artist depends on what the contents of that String array is. Did you bother to look? I would guess that each element would contain a label and a value so, in that case, you would obviously need to find the elements with the labels you are interested in and get the corresponding values. How you process data depends on that data so you need to have a clear understanding of the structure of that data. If you want us to help you then you need to provide us with that same clear understanding, i.e. show us the data you're working with.
Sorry jmcilhinney. Miss understood what you stated. Not sure why but I am unable to extract the stream data. Nothing is coming up in the console, that which would not surprise me. (Self teaching VB) I am probably putting the code information in the wrong spot.
-
Oct 18th, 2020, 03:02 PM
#6
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Figured out one issue. Figured out where to put it I have a function called refresh_Tags() but for some reason still not pulling the metadata info from the stream.
Code:
Try
Timer1.Stop()
Bass.BASS_ChannelStop(stream)
stream = Bass.BASS_StreamCreateURL("http://shaincast.caster.fm:37405/listen.mp3?authn1124b16fbd1cfa0fccd03d9d0c68fd32", 0, BASSFlag.BASS_DEFAULT, Nothing, IntPtr.Zero)
Bass.BASS_ChannelPlay(stream, False)
refresh_Tags()
Timer1.Start()
Catch ex As Exception
MsgBox("Provided Link Could Not Be Played!!")
' Timer1.Start()
End Try
Code:
Function refresh_Tags()
Try
Dim tags As String() = Bass.BASS_ChannelGetTagsICY(stream)
If tags Is Nothing Then
' try http...
tags = Bass.BASS_ChannelGetTagsHTTP(stream)
End If
If Not (tags Is Nothing) Then
Dim tag As String
For Each tag In tags
Console.WriteLine(tag)
Next tag
End If
End If
-
Oct 18th, 2020, 06:07 PM
#7
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Almost got it. Would help if I actually included the stream url in the the tag refresh function
Code:
Dim stream As Integer = Bass.BASS_StreamCreateURL("http://shaincast.caster.fm:37405/listen.mp3?authn1124b16fbd1cfa0fccd03d9d0c68fd32", 0,
BASSFlag.BASS_STREAM_STATUS, Nothing, IntPtr.Zero)
Dim tags As String() = Bass.BASS_ChannelGetTagsMETA(stream)
If tags Is Nothing Then
' try http...
tags = Bass.BASS_ChannelGetTagsHTTP(stream)
End If
If Not (tags Is Nothing) Then
Dim tag As String
For Each tag In tags
Console.WriteLine(tag)
Next tag
End If
Example of output: StreamTitle='Judy Garland - Have Yourself A Merry Little Christmas';StreamUrl='&artist=Judy%20Garland&title=Have%20Yourself%20A%20Merry%20Little%20Christmas& album=100%20Classic%20Christmas%20Songs&duration=164754&songtype=S&overlay=NO&buycd=&website=&pictur e=az_99_100%20Classic%20Christmas%20Songs_Judy%20Garland.jpg';
-
Oct 18th, 2020, 06:57 PM
#8
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Originally Posted by SkyRanger
Example of output: StreamTitle='Judy Garland - Have Yourself A Merry Little Christmas';StreamUrl='&artist=Judy%20Garland&title=Have%20Yourself%20A%20Merry%20Little%20Christmas& album=100%20Classic%20Christmas%20Songs&duration=164754&songtype=S&overlay=NO&buycd=&website=&pictur e=az_99_100%20Classic%20Christmas%20Songs_Judy%20Garland.jpg';
So you can now see where the artist and title are in that data so you just need to do a bit of string manipulation to get them out.
-
Oct 18th, 2020, 07:43 PM
#9
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
lol. That is going to be the fun part, brain is starting to hurt already. Then I need to figure out how to do auto song title and artist refresh after song change
-
Oct 18th, 2020, 08:07 PM
#10
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Without even considering regular expressions, you could use IndexOf to find "StreamTitle=" and the subsequent closing single-quote, then use Substring to get the text between the quotes, then use Split to separate the artist and title on the " - " substring. Each step is elementary, which is why it's important to break it down into steps. the hurting head results when you try to look at a multi-step process as a single step.
-
Oct 21st, 2020, 09:02 PM
#11
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Almost got it. I have it showing the new song in the Notification bubble but not changing in player. Not sure what I am missing.
Code:
Function PlayPause()
If stream <> 0 Then
If Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING Then
Bass.BASS_ChannelPause(stream)
ThumbnailButton2.Image = My.Resources.Media_Controls_Play_icon
Else
Bass.BASS_ChannelPlay(stream, False)
ThumbnailButton2.Image = My.Resources.Media_Controls_Pause_icon
Timer1.Start()
Timer2.Start()
End If
Else
Try
'Timer1.Stop()
Bass.BASS_ChannelStop(stream)
stream = Bass.BASS_StreamCreateURL("http://shaincast.caster.fm:37405/listen.mp3?authn6ce7fc2942ccbbbd15c5f754727fb526", 0, BASSFlag.BASS_STREAM_AUTOFREE, Nothing, IntPtr.Zero)
Bass.BASS_ChannelPlay(stream, False)
_mysync = New SYNCPROC(AddressOf refresh_Tags)
Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mysync, IntPtr.Zero)
refresh_Tags()
'MetaSync()
'Timer1.Start()
Catch ex As Exception
MsgBox("Provided Link Could Not Be Played!!")
' Timer1.Start()
End Try
End If
End Function
Function refresh_Tags()
Try
Dim Tag As New Un4seen.Bass.AddOn.Tags.TAG_INFO()
Un4seen.Bass.AddOn.Tags.BassTags.BASS_TAG_GetFromURL(stream, Tag)
'Dim channelinf As Un4seen.Bass.BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
If Not Tag.title = "" Then
Try
NotifyIcon1.BalloonTipText = Tag.title
NotifyIcon1.ShowBalloonTip(2000)
Catch ex As Exception
End Try
End If
Try
'last_Title = tag.title
If Not Tag.title = "" Then
Text = Tag.title
Else
Text = "Christmas_Music_Broadcast"
titlelabel.Text = "Title:Not Found"
End If
If Tag.title.Length > 30 Then
LabelControl1.Text = Tag.title.Substring(0, 30) + "..."
titlelabel.Text = Tag.title
Else
LabelControl1.Text = Tag.title
titlelabel.Text = Tag.title
End If
Catch ex As Exception
LabelControl1.Text = "Christmas_Music_Broadcast"
titlelabel.Text = "Title : Not Found"
Text = "Christmas_Music_Broadcast"
End Try
Try
If Not Tag.album = "" Then
albumLabel.Text = Tag.album
Else
albumLabel.Text = "Album:Not Found"
End If
Catch ex As Exception
albumLabel.Text = "No Data"
End Try
Try
If Not Tag.artist = String.Empty Then
ArtistLabel.Text = Tag.artist
Else
ArtistLabel.Text = "Artist:Not Found"
End If
Catch ex As Exception
ArtistLabel.Text = "No Data"
End Try
Try
Dim abort As System.Drawing.Image.GetThumbnailImageAbort
'PictureBox1.Image = Tag.PictureGetImage(0).GetThumbnailImage(207, 192, abort, IntPtr.Zero)
artwork = Tag.PictureGetImage(0)
'albumArtImg = Tag.PictureGetImage(0).GetThumbnailImage(207, 192, abort, IntPtr.Zero)
'Me.BackgroundImage = Tag.PictureGetImage(0).GetThumbnailImage(207, 192, abort, IntPtr.Zero)
Try
BlurBitmap(Me.BackgroundImage, 3)
Catch ex As Exception
Me.BackgroundImage = My.Resources.winter_background
End Try
Catch ex As Exception
Me.BackgroundImage = My.Resources.winter_background
PictureBox1.Image = My.Resources.bell_music
artwork = My.Resources.bell_music
albumArtImg = My.Resources.bell_music
End Try
LabelControl1.Text = Tag.title
Catch ex As Exception
End Try
End Function
-
Oct 22nd, 2020, 05:19 PM
#12
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
I think I may have found the error. Visual Studio is throwing this:
System.InvalidOperationException: 'Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.'
It is throwing it on this:
Code:
If Not Tag.title = "" Then
Text = Tag.title
-
Oct 22nd, 2020, 06:53 PM
#13
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
VS isn't throwing anything. It's your app that's throwing the exception. That suggests that your are using a Timers.Timer, which raises its Elapsed event on a background thread, rather than a Windows.Forms.Timer, which raises its Tick event on the UI thread. If there isn't much work to do in the event handler and all or most of it will affect the UI then use a Windows.Forms.Timer and the issue goes away. If you do have significant work to do that won't affect the UI then using a Timers.Timer is a good idea but you then need to marshal a method call to the UI thread in order to do work that does affect the UI. In its simplest form, that might look like this:
vb.net Code:
'Do work that doesn't affect the UI here.
BeginInvoke(Sub()
'Do work that does affect the UI here.
End Sub)
'Do more work that doesn't affect the UI here.
For more detailed information, follow the CodeBank link in my signature below and check out my thread on Accessing Controls From Worker Threads.
-
Oct 22nd, 2020, 07:02 PM
#14
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
OMG jmcilhinney you are awesome. I lost track how long I have been working on this. it works. It actually works...lol
-
Oct 22nd, 2020, 07:43 PM
#15
Thread Starter
Member
Re: BASS_ChannelGetTags and BASS_ChannelSetSync
Got to excited too fast. Been searching the web for the answer but no luck. Trying to figure a way that when the user opens the player it will check to see if the stream is Live or not.
Code:
shoutstream = http://shaincast.caster.fm:37405/listen.mp3?authn6ce7fc2942ccbbbd15c5f754727fb526
If shoutstream is onilne live.text = "Live"
Else live.text = "Offline"
Have no clue on how to work that in.
-
Oct 23rd, 2020, 04:54 AM
#16
Re: [RESOLVED] BASS_ChannelGetTags and BASS_ChannelSetSync
I suppose by "live", you mean already reading ? in this case, the file is open in you application, you can check for that.
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Oct 23rd, 2020, 05:43 PM
#17
Thread Starter
Member
Re: [RESOLVED] BASS_ChannelGetTags and BASS_ChannelSetSync
I am working on setting us so that if the listener leaves the program open it will state if the stream is online or not. That it will change automatically if the server goes offline or online with a stream.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|