Trancedified
asked on
Importing .WMA file into VB
Hello,
I have a .WMA file and if you open it with notepad you can see some header information like the date, time started, time ended etc.
Is there a way to import this file into VB kind of like notepad and copy it to a listbox? The text looks kinda like this:
0&²uŽfϦ٠ª bÎlÎ @¤ÐÒãÒ—ð É^¨P O L Y M P U S âdss 4692 þÿÿÿÿÿ04062911501504062911 5019000004 ÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿ, ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ j ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ
I need to grab this:
04062911501504062911501900 0004
Thanks for your tips!
Chris
I have a .WMA file and if you open it with notepad you can see some header information like the date, time started, time ended etc.
Is there a way to import this file into VB kind of like notepad and copy it to a listbox? The text looks kinda like this:
0&²uŽfϦ٠ª bÎlÎ @¤ÐÒãÒ—ð É^¨P O L Y M P U S âdss 4692 þÿÿÿÿÿ04062911501504062911
I need to grab this:
04062911501504062911501900
Thanks for your tips!
Chris
ASKER
Hey Bob,
Nice to hear from you again!
This piece:
O L Y M P U S âdss 4692
Has an ID number I want to extract (4692)
Ok this piece has the year, month day, plus the time this .wma file was created, and when it ended. Here's the format:
04062911501504062911501900 0004
Translated:
04 (year)
06 (month)
29 (day)
Created: 11:50:15
Duration: 040629 (seconds? milliseconds?)
Ended: 11:50:19 (so this audio file lasted for 4 seconds)
000004 (ignore it)
I tried using the below code to load the text into a textbox but it only gave me:
0&uf
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare any variables
Dim sFileName As String = "C:\Documents and Settings\Chris\My Documents\Chris\Work\WMA\S amples\469 20032.wma"
Dim myFileStream As New System.IO.FileStream(sFile Name, _
FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)
'Create the StreamReader and associate the filestream with it
Dim myReader As New System.IO.StreamReader(myF ileStream)
'Read the entire text, and set it to a string
Dim sFileContents As String = myReader.ReadToEnd
'Print it to the textbox
txtFileDisplay.text = sFileContents
End Sub
I was hoping to get exactly what I had above if I opened it up in notepad:
0&²uŽfϦ٠ª bÎlÎ @¤ÐÒãÒ—ð É^¨P O L Y M P U S âdss 4692 þÿÿÿÿÿ04062911501504062911 5019000004 ÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿ, ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ j ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿ
But it didn't work, any ideas?
Nice to hear from you again!
This piece:
O L Y M P U S âdss 4692
Has an ID number I want to extract (4692)
Ok this piece has the year, month day, plus the time this .wma file was created, and when it ended. Here's the format:
04062911501504062911501900
Translated:
04 (year)
06 (month)
29 (day)
Created: 11:50:15
Duration: 040629 (seconds? milliseconds?)
Ended: 11:50:19 (so this audio file lasted for 4 seconds)
000004 (ignore it)
I tried using the below code to load the text into a textbox but it only gave me:
0&uf
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare any variables
Dim sFileName As String = "C:\Documents and Settings\Chris\My Documents\Chris\Work\WMA\S
Dim myFileStream As New System.IO.FileStream(sFile
FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)
'Create the StreamReader and associate the filestream with it
Dim myReader As New System.IO.StreamReader(myF
'Read the entire text, and set it to a string
Dim sFileContents As String = myReader.ReadToEnd
'Print it to the textbox
txtFileDisplay.text = sFileContents
End Sub
I was hoping to get exactly what I had above if I opened it up in notepad:
0&²uŽfϦ٠ª bÎlÎ @¤ÐÒãÒ—ð É^¨P O L Y M P U S âdss 4692 þÿÿÿÿÿ04062911501504062911
But it didn't work, any ideas?
You have to import
Imports System.io
Imports System.Text
'This code reads the first file 30 lines of the file and converts the lines to ASCII chars in order to be easy to read them
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sFileName As String = "C:\Documents and Settings\Chris\My Documents\Chris\Work\WMA\S amples\469 20032.wma"
Dim ascii As Encoding = Encoding.ASCII
Dim [unicode] As Encoding = Encoding.Unicode
' Convert the string into a byte[].
Dim unicodeBytes As Byte()
' Perform the conversion from one encoding to the other.
Dim asciiBytes As Byte()
' Convert the new byte[] into a char[] and then into a string.
' This is a slightly different approach to converting to illustrate
' the use of GetCharCount/GetChars.
Dim asciiChars() As Char
Dim fr As StreamReader
Dim sbr As New StringBuilder
Dim FileString As String
FileString = ""
Try
Dim i As Integer
fr = New StreamReader(sFileName)
For i = 0 To 30
FileString = fr.ReadLine
If Not IsNothing(FileString) Then
unicodeBytes = [unicode].GetBytes(FileStr ing)
asciiBytes = Encoding.Convert([unicode] , ascii, unicodeBytes)
ReDim asciiChars(ascii.GetCharCo unt(asciiB ytes, 0, asciiBytes.Length))
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0)
sbr.Append(asciiChars)
Else
Exit For
End If
Next
Finally
fr.Close()
End Try
txtFileDisplay.Text = sbr.ToString
End Sub
Imports System.io
Imports System.Text
'This code reads the first file 30 lines of the file and converts the lines to ASCII chars in order to be easy to read them
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sFileName As String = "C:\Documents and Settings\Chris\My Documents\Chris\Work\WMA\S
Dim ascii As Encoding = Encoding.ASCII
Dim [unicode] As Encoding = Encoding.Unicode
' Convert the string into a byte[].
Dim unicodeBytes As Byte()
' Perform the conversion from one encoding to the other.
Dim asciiBytes As Byte()
' Convert the new byte[] into a char[] and then into a string.
' This is a slightly different approach to converting to illustrate
' the use of GetCharCount/GetChars.
Dim asciiChars() As Char
Dim fr As StreamReader
Dim sbr As New StringBuilder
Dim FileString As String
FileString = ""
Try
Dim i As Integer
fr = New StreamReader(sFileName)
For i = 0 To 30
FileString = fr.ReadLine
If Not IsNothing(FileString) Then
unicodeBytes = [unicode].GetBytes(FileStr
asciiBytes = Encoding.Convert([unicode]
ReDim asciiChars(ascii.GetCharCo
ascii.GetChars(asciiBytes,
sbr.Append(asciiChars)
Else
Exit For
End If
Next
Finally
fr.Close()
End Try
txtFileDisplay.Text = sbr.ToString
End Sub
ASKER
wguerram,
Thanks for trying, it gave me the same result:
0&uf
Check this out though:
1) If I converted the .wma file to a .txt, opened it up in notepad
2) Deleted the first line in notepad
3) Save it (keep notepad open)
4) Run the code again, it reads into the textbox perfectly
5) Go back to notepad undo the delete
6) Run the code again, it reads into the textbox
VERY VERY VERY weird huh? Do you know why?
Chris
Thanks for trying, it gave me the same result:
0&uf
Check this out though:
1) If I converted the .wma file to a .txt, opened it up in notepad
2) Deleted the first line in notepad
3) Save it (keep notepad open)
4) Run the code again, it reads into the textbox perfectly
5) Go back to notepad undo the delete
6) Run the code again, it reads into the textbox
VERY VERY VERY weird huh? Do you know why?
Chris
This shoul do it
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sFileName As String = "C:\Documents and Settings\Chris\My Documents\Chris\Work\WMA\S amples\469 20032.wma"
'Dim ascii As Encoding = Encoding.ASCII
Dim [unicode] As Encoding = Encoding.Unicode
' Convert the string into a byte[].
Dim unicodeBytes As Byte()
' Perform the conversion from one encoding to the other.
'Dim asciiBytes As Byte()
' Convert the new byte[] into a char[] and then into a string.
' This is a slightly different approach to converting to illustrate
' the use of GetCharCount/GetChars.
'Dim asciiChars() As Char
Dim fr As StreamReader
Dim sbr As New StringBuilder
Dim FileString As String
FileString = ""
Try
Dim i As Integer
fr = New StreamReader(sFileName)
For i = 0 To 30
FileString = fr.ReadLine
If Not IsNothing(FileString) Then
unicodeBytes = [unicode].GetBytes(FileStr ing)
'asciiBytes = Encoding.Convert([unicode] , ascii, unicodeBytes)
'ReDim asciiChars(ascii.GetCharCo unt(asciiB ytes, 0, asciiBytes.Length))
'ascii.GetChars(asciiBytes , 0, asciiBytes.Length, asciiChars, 0)
sbr.Append([unicode].GetCh ars(unicod eBytes))
Else
Exit For
End If
Next
Finally
fr.Close()
End Try
txtFileDisplay.Text = sbr.ToString
End sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sFileName As String = "C:\Documents and Settings\Chris\My Documents\Chris\Work\WMA\S
'Dim ascii As Encoding = Encoding.ASCII
Dim [unicode] As Encoding = Encoding.Unicode
' Convert the string into a byte[].
Dim unicodeBytes As Byte()
' Perform the conversion from one encoding to the other.
'Dim asciiBytes As Byte()
' Convert the new byte[] into a char[] and then into a string.
' This is a slightly different approach to converting to illustrate
' the use of GetCharCount/GetChars.
'Dim asciiChars() As Char
Dim fr As StreamReader
Dim sbr As New StringBuilder
Dim FileString As String
FileString = ""
Try
Dim i As Integer
fr = New StreamReader(sFileName)
For i = 0 To 30
FileString = fr.ReadLine
If Not IsNothing(FileString) Then
unicodeBytes = [unicode].GetBytes(FileStr
'asciiBytes = Encoding.Convert([unicode]
'ReDim asciiChars(ascii.GetCharCo
'ascii.GetChars(asciiBytes
sbr.Append([unicode].GetCh
Else
Exit For
End If
Next
Finally
fr.Close()
End Try
txtFileDisplay.Text = sbr.ToString
End sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, what is the most important information here?
You can get a lot of information very easily using the Windows Media Player v.9 COM control:
WM/Year
WM/TrackNumber
WM/Lyrics
WM/Genre
WM/Composer
WM/AlbumTitle
Title
SourceURL
Is_Protected
FileSize
Duration
CurrentBitrate
Author
durationstring
Bob
You can get a lot of information very easily using the Windows Media Player v.9 COM control:
WM/Year
WM/TrackNumber
WM/Lyrics
WM/Genre
WM/Composer
WM/AlbumTitle
Title
SourceURL
Is_Protected
FileSize
Duration
CurrentBitrate
Author
durationstring
Bob
ASKER
Bob,
I'm trying the Windows Media Player approach I got to this page:
http://www.msdn.microsoft.com/library/default.asp?url=/downloads/list/winmedia.asp
But which one do I download? I got the Platform SDK and it seems it's more for the server side for your website to play media files?
This one is for C++ or C#, is there anything for VB.NET?
http://www.microsoft.com/downloads/details.aspx?FamilyID=e43cbe59-678a-458a-86a7-ff1716fad02f&DisplayLang=en
Thanks for the tip!
wguerram,
The code produced the same results.
I'm trying the Windows Media Player approach I got to this page:
http://www.msdn.microsoft.com/library/default.asp?url=/downloads/list/winmedia.asp
But which one do I download? I got the Platform SDK and it seems it's more for the server side for your website to play media files?
This one is for C++ or C#, is there anything for VB.NET?
http://www.microsoft.com/downloads/details.aspx?FamilyID=e43cbe59-678a-458a-86a7-ff1716fad02f&DisplayLang=en
Thanks for the tip!
wguerram,
The code produced the same results.
This one can be use through the framework VB .NET or C# .NET
http://www.microsoft.com/downloads/details.aspx?FamilyID=e43cbe59-678a-458a-86a7-ff1716fad02f&DisplayLang=en
http://www.microsoft.com/downloads/details.aspx?FamilyID=e43cbe59-678a-458a-86a7-ff1716fad02f&DisplayLang=en
ASKER
OK after installing it, going to Programs > Microsoft Visual Studio.NET 2003 > Visual Studio.NET Tools > Visual Studio.NET 2003 Command Prompt
Paste this in:
regasm C:\WMSDK\WMPSDK9\redist\wm ppia.dll
<Successful>
Paste this in:
Gacutil /i C:\WMSDK\WMPSDK9\redist\wm ppia.dll
<Successful>
Create a new C# windows app, go to the toolbox > COM components tab > Windows Media Player (click the checkbox) > OK
Drag the mediaplayer to the form then I get the error message:
"One or more of the types in the assembly unable to load."
What can I do now?
Chris
Paste this in:
regasm C:\WMSDK\WMPSDK9\redist\wm
<Successful>
Paste this in:
Gacutil /i C:\WMSDK\WMPSDK9\redist\wm
<Successful>
Create a new C# windows app, go to the toolbox > COM components tab > Windows Media Player (click the checkbox) > OK
Drag the mediaplayer to the form then I get the error message:
"One or more of the types in the assembly unable to load."
What can I do now?
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow getting closer:
So if I was to use your sub, ReadWMAInformation:
ReadWMAInformation("C:\Doc uments and Settings\Chris\My Documents\Chris\Work\WMA.N ET\Samples \46920033. wma", ) <-----
What is inputted in the second parameter?
Chris
So if I was to use your sub, ReadWMAInformation:
ReadWMAInformation("C:\Doc
What is inputted in the second parameter?
Chris
This is what I have as a test:
Dim fileInfo As WMAInformation = New WMAInformation
ReadWMAInformation("C:\Doc uments and Settings\All Users\Documents\My Music\Sample Music\New Stories (Highway Blues).wma", fileInfo)
Bob
Dim fileInfo As WMAInformation = New WMAInformation
ReadWMAInformation("C:\Doc
Bob
ASKER
Bob, I got it working.
Is there a way to retrieve the Date of Creation & Time of creation?
(easiest way is right clicking the file > properties, but I want to do it through code)
Chris
Is there a way to retrieve the Date of Creation & Time of creation?
(easiest way is right clicking the file > properties, but I want to do it through code)
Chris
Public Function GetFileCreationTime(ByVal pathFile As String) As Date
Dim dateCreation As Date
Try
Dim infoSelectedFile As System.IO.FileInfo = New System.IO.FileInfo(pathFil e)
dateCreation = infoSelectedFile.CreationT ime
Catch ex As Exception
MessageBox.Show(ex.ToStrin g)
End Try
Return dateCreation
End Function 'GetFileCreationTime'
Bob
Dim dateCreation As Date
Try
Dim infoSelectedFile As System.IO.FileInfo = New System.IO.FileInfo(pathFil
dateCreation = infoSelectedFile.CreationT
Catch ex As Exception
MessageBox.Show(ex.ToStrin
End Try
Return dateCreation
End Function 'GetFileCreationTime'
Bob
Bob