Error with UltraID3Lib VB - vb.net

Well I get this error (The ID3v2TagVersions value of '4' (4) is not valid for this operation.) with UltraID3Lib on Visual Basic 2013. I want to use this library (dll) so i can edit my mp3 tags in a mp3 file. Although I achived changing the tags , when i use the Clear() sub and then retry to change the tags i get this error. Can anyone help me ?
My Code
Private Sub btnExecute_Click(sender As Object, e As EventArgs) Handles btnExecute.Click
Dim Artist As String = ""
Dim Title As String = ""
Dim MP3TagEditor As New UltraID3
For Each Path In MP3List
MP3TagEditor.Read(Path)
Title = "Somthing"
Artist = "Somthing"
MP3TagEditor.ID3v2Tag.Title = Title
MP3TagEditor.ID3v2Tag.Artist = Artist
MP3TagEditor.Clear()
MP3TagEditor.Write()
Next
MsgBox("Tags Added", MsgBoxStyle.Information, "Success")
End Sub
Thanks

Try this
Dim sTitle As String = "No Name"
Dim sSinger As String = ""
Dim sAlbum As String = ""
Dim sYear As String = ""
Dim sComm As String = ""
Dim MP3Tag As New UltraID3
MP3Tag.Read(YOUR_PATH)
Try
Dim pics = MP3Tag.ID3v2Tag.Frames.GetFrames(CommonMultipleInstanceID3v2FrameTypes.Picture)
AlbumPic.Image = CType(pics(0), ID3v2PictureFrame).Picture
Catch ex As Exception
AlbumPic.Image = My.Resources.FlatCD
End Try
Try
sTitle = MP3Tag.Title
sSinger = MP3Tag.Artist
sAlbum = MP3Tag.Album
Catch ex As Exception
End Try

You cannot read ID3v2.4 tags from an MP3 file with UltraID3Lib. It doesn't support it yet. (As of 31/12/2015).
But there is an alternative, which, in my humble opinion is even better, stable and efficacious:
TagLib-Sharp
It supports many other tag types as well apart from ID3, i.e, MP3 Files.
A quick example to get you on the way:
Dim f As TagLib.File = TagLib.File.Create("someFile.mp3")
Dim artist As String = f.Tag.JoinedPerformers
Dim title As String = f.Tag.Title
More resources for TagLib-Sharp:
Where can I find tag lib sharp examples?
Set Bitmap as cover art for MP3

Related

AxWMPlib: How to load playlist from an external file

I am making a media player application using AXWMPlib which has a playlist.
what i successfully able to do was saving the playlist items in a text file.
below is the code for saving:
If SavePlaylist.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim writefile As New System.IO.StreamWriter(SavePlaylist.FileName)
For i = 0 To lstview.Items.Count - 2
writefile.WriteLine(Form1.main.AxWMP1.currentPlaylist.Item(i).sourceURL)
Next
writefile.Write(Form1.main.AxWMP1.currentPlaylist.Item(Form1.main.AxWMP1.currentPlaylist.count - 1).sourceURL)
writefile.Close()
End If
for loading i wrote till here:
If OpenPlaylist.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim readfile As New System.IO.StreamReader(OpenPlaylist.FileName)
Dim ob As String = readfile.ReadToEnd()
Dim content() As String = OpenPlaylist.FileName.Split(Environment.NewLine)
End If
i dont know how to read the lines stored in current() and append them in current playlist.
found a solution:
If Open.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim readfile As New System.IO.StreamReader(Open.FileName)
Dim ob As String = readfile.ReadToEnd()
Dim content() As String = ob.Split(Environment.NewLine)
For Each Line As String In content
Dim item As IWMPMedia = Form1.AxWMP1.newMedia(Line)
Form1.AxWMP1.currentPlaylist.appendItem(item)
Next
End If

VB.NET Return Form Object using Form Name

I'm basically writing a custom Error Logging Form for one of my applications because users cannot be trusted to report the errors to me.
I am obtaining the Form Name using the 'MethodBase' Object and then getting the DeclaringType Name.
Dim st As StackTrace = New StackTrace()
Dim sf As StackFrame = st.GetFrame(1)
Dim mb As MethodBase = sf.GetMethod()
Dim dt As String = mb.DeclaringType.Name
How can I then use this to obtain the Form Object so I can pass this to my 'screenshot method' that screenshots the particular form referenced.
Public Sub SaveAsImage(frm As Form)
'Dim fileName As String = "sth.png"
'define fileName
Dim format As ImageFormat = ImageFormat.Png
Dim image = New Bitmap(frm.Width, frm.Height)
Using g As Graphics = Graphics.FromImage(image)
g.CopyFromScreen(frm.Location, New Point(0, 0), frm.Size)
End Using
image.Save(_LogPath & Date.Now.ToString("ddMMyyyy") & ".png", format)
End Sub
I posted the same solution to a similar question. Try this:
Dim frm = Application.OpenForms.Item(dt)

CovrageInfo.CreateFromFile is giving an error

I have replicated the code from the example to collect the result for code coverage from Here except that my code is vb.net
Here is my code
Imports Microsoft.VisualStudio.Coverage.Analysis
Module Module1
Sub Main()
Using info As CoverageInfo = CoverageInfo.CreateFromFile("C:MyFile\data.coverage")
Dim lines As New List(Of BlockLineRange)()
For Each [module] As ICoverageModule In info.Modules
Dim coverageBuffer As Byte() = [module].GetCoverageBuffer(Nothing)
Using reader As ISymbolReader = [module].Symbols.CreateReader()
Dim methodId As UInteger = 0
Dim MethodName As String = ""
Dim undecoratedMethodName As String = ""
Dim ClassName As String = ""
Dim NameSpaceName As String = ""
lines.Clear()
While reader.GetNextMethod(methodId, MethodName, undecoratedMethodName, ClassName, NameSpaceName, lines)
Dim stats As CoverageStatistics = CoverageInfo.GetMethodStatistics(coverageBuffer, lines)
Console.WriteLine("Method {0}{1}{2}{3}{4} has:" & NameSpaceName & ClassName & undecoratedMethodName)
Console.WriteLine(" blocks covered are {0}", stats.BlocksCovered)
End While
End Using
Next
End Using
End Sub
End Module
When I run this on the line for CreateFromFile i get a ImageNotFoundException
Image File "C:\SomeAddress\MyServer\UnitTest.dll" could not be found
I have already as per instructions added the neccessary dlls to my project copied and the other 2 as references.
And yet another tumbleweed moment....
Basically the problem was that folder containing my coverage file also had to contains all the dlls used within that assembely that tests were ran on in order to create that object.
hope this helps you if you ever stumbled over this issuen :)

Converting UTF8 to ANSI?

I'd like to download a webpage using .Net's WebClient class, extract the title (i.e. what's between <title> and </title>) and save the page to a file.
The problem is, the page is encoded in UTF-8 and the System.IO.StreamWriter throws an exception when using a filename with such characters.
I've googled and tried several ways to convert UTF8 to ANSI, to no avail. Does someone have working code for this?
'Using WebClient asynchronous downloading
Private Sub AlertStringDownloaded(ByVal sender As Object,
ByVal e As DownloadStringCompletedEventArgs)
If e.Cancelled = False AndAlso e.Error Is Nothing Then
Dim Response As String = CStr(e.Result)
'Doesn't work
Dim resbytes() As Byte = Encoding.UTF8.GetBytes(Response)
Response = Encoding.Default.GetString(Encoding.Convert(Encoding.UTF8,
Encoding.Default, resbytes))
Dim title As Regex = New Regex("<title>(.+?) \(",
RegexOptions.Singleline)
Dim m As Match
m = title.Match(Response)
If m.Success Then
Dim MyTitle As String = m.Groups(1).Value
'Illegal characters in path.
Dim objWriter As New System.IO.StreamWriter("c:\" & MyTitle & ".txt")
objWriter.Write(Response)
objWriter.Close()
End If
End If
End Sub
Edit: Thanks everyone for the help. It turns out the error was not due to UTF8 but rather a hidden LF character in title section of the page, which is obviously an illegal character in a path.
Edit: Here's a simple way to remove some of the illegal characters in a filename/path:
Dim MyTitle As String = m.Groups(1).Value
Dim InvalidChars As String = New String(Path.GetInvalidFileNameChars()) + New String(Path.GetInvalidPathChars())
For Each c As Char In InvalidChars
MyTitle = MyTitle.Replace(c.ToString(), "")
Next
Edit: And here's how to tell WebClient to expect UTF-8:
Dim webClient As New WebClient
AddHandler webClient.DownloadStringCompleted, AddressOf AlertStringDownloaded
webClient.Encoding = Encoding.UTF8
webClient.DownloadStringAsync(New Uri("www.acme.com"))
I don't think the problem is related to UTF-8. I think your regex will include </title> if it appears on the same line. The characters<> are invalid in a Windows filename.
If this is not the problem it would be helpful to see some sample input and output values of MyTitle.

Passing radio button parameter to another function in vb.net

I have 2 functions, one is SaveData() and the other is SendEmail()
in the SaveData() the radio buttons that are selected are saved, and the SendMail() is called at the end.
in the SendMail() the radio buttons are "tested" and then one of two emails is sent out based on the radio choices.
The problem I am having is passing the parameters correctly. I have tried several different method but the parameters are not being sent to SendMail()
The radio buttons are Yes/No questions
Any thoughts on why the parameters are not being passed?
Here is what I have:
Protected Function SaveData()
...
Q1 = Me.rblnewqst1.SelectedValue
Q2 = Me.rblnewqst2.SelectedValue
Q3 = Me.rblnewqst3.SelectedValue
Q4 = Me.rblnewqst4.SelectedValue
Q5 = Me.rblnewqst5.SelectedValue
....
and the SendEmail() is
Protected Sub SendEmail(ByVal rblnewqst1 As Object, ByVal rblnewqst2 As Object, ByVal rblnewqst3 As Object, ByVal rblnewqst4 As Object, ByVal rblnewqst5 As Object)
If rblnewqst1.SelectedValue = 2 Or rblnewqst2.SelectedValue = 2 Or rblnewqst3.SelectedValue = 2 Or rblnewqst4.SelectedValue = 2 Or rblnewqst5.SelectedValue = 2 Then
Dim sResponseFromName As String = "ex#example.com"
Dim sResponseToName As String = txtEmail.Text
Dim sResponseSubject As String = "Denied"
Dim sResponseBody As String = "Message>"
Try
Dim mm As New MailMessage(sResponseFromName, sResponseToName)
Dim SMTP As New SmtpClient
SMTP.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
mm.Subject = sResponseSubject
mm.Body = sResponseBody
mm.IsBodyHtml = True
Try
SMTP.Send(mm)
Catch exSmtpException As SmtpException
Dim stemp As String = exSmtpException.Message.ToString
End Try
Catch ex As ApplicationException
Dim stemp As String = ex.InnerException.Message.ToString
End Try
Else
Dim sResponseFromName As String = "ex#example.com"
Dim sResponseToName As String = txtEmail.Text
Dim sResponseSubject As String = "Accepted"
Dim sResponseBody As String = "MESSAGE....."
Try
Dim mm As New MailMessage(sResponseFromName, sResponseToName)
Dim SMTP As New SmtpClient
SMTP.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
mm.Subject = sResponseSubject
mm.Body = sResponseBody
mm.IsBodyHtml = True
Try
SMTP.Send(mm)
Catch exSmtpException As SmtpException
Dim stemp As String = exSmtpException.Message.ToString
End Try
Catch ex As ApplicationException
Dim stemp As String = ex.InnerException.Message.ToString
End Try
End If
End Sub
Like HardCode mentioned in his comments, I do recommend you always work with Option Explicit and Option Strict on.
The first thing I would do is alter the way the SendMail part works, to take the values from the radio buttons. Your If is checking against and integer value, so I would use Integer as the type.
So something more like:
Protected Sub SendEmail(ByVal q1 As Integer, ByVal q2 As Integer)
If q1 = 2 Or q2 = 2 Then
etc...
End IF
I shortened the list so I didn't have to type as much. In general I think it is better practice to send values than entire objects, unless you need the entire control for a specific reason. Also, sending object isn't something I recommend doing unless you have no other choice.
The other thing I would recommend, to test it, is setting a break point just inside the sendEmail Sub, use quick watch to see what the actual objects/types are that are being sent to your method that you are checking.