Solved

Importing .WMA file into VB

Posted on 2004-08-31
15
553 Views
Last Modified: 2008-03-06
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                þÿÿÿÿÿ040629115015040629115019000004ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ, ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿj  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ  

I need to grab this:

040629115015040629115019000004

Thanks for your tips!

Chris
0
Comment
Question by:Trancedified
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
15 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11945160
What information are you trying to get?

Bob
0
 
LVL 1

Author Comment

by:Trancedified
ID: 11945342
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:
040629115015040629115019000004
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\Samples\46920032.wma"
        Dim myFileStream As New System.IO.FileStream(sFileName, _
            FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)

        'Create the StreamReader and associate the filestream with it
        Dim myReader As New System.IO.StreamReader(myFileStream)

        '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                þÿÿÿÿÿ040629115015040629115019000004ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ, ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿj  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ  

But it didn't work, any ideas?
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11947469
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\Samples\46920032.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(FileString)
                        asciiBytes = Encoding.Convert([unicode], ascii, unicodeBytes)
                        ReDim asciiChars(ascii.GetCharCount(asciiBytes, 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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Trancedified
ID: 11947681
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
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11947748
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\Samples\46920032.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(FileString)
                    'asciiBytes = Encoding.Convert([unicode], ascii, unicodeBytes)
                    'ReDim asciiChars(ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length))
                    'ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0)
                    sbr.Append([unicode].GetChars(unicodeBytes))
                Else
                    Exit For
                End If
            Next
        Finally
            fr.Close()
        End Try

        txtFileDisplay.Text = sbr.ToString
End sub
0
 
LVL 8

Assisted Solution

by:wguerram
wguerram earned 200 total points
ID: 11947839
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11951728
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
0
 
LVL 1

Author Comment

by:Trancedified
ID: 11954678
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.

0
 
LVL 8

Expert Comment

by:wguerram
ID: 11954724
0
 
LVL 1

Author Comment

by:Trancedified
ID: 11955808
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\wmppia.dll
<Successful>

Paste this in:
Gacutil /i C:\WMSDK\WMPSDK9\redist\wmppia.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
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 300 total points
ID: 11955870
I do this in VB6 all the time.  Download the Windows Media Player 9 from Micro$oft.  Add a COM reference to the Windows Media Player type library (wmp.dll).  

A COM wrapper will be created, called WMPLib.  

Add the following code:

  Public Structure WMAInformation
    Public Duration As String
    Public Author As String
    Public CurrentBitRate As String
    Public FileSize As String
    Public Is_Protected As Boolean
    Public SourceURL As String
    Public Title As String
    Public WM_AlbumTitle As String
    Public WM_Composer As String
    Public WM_Genre As String
    Public WM_Lyrics As String
    Public WM_TrackNumber As Integer
    Public WM_Year As Integer
  End Structure 'WMAInformation'


  Public Sub ReadWMAInformation(ByVal pathMedia As String, ByRef fileInfo As WMAInformation)

    Try

      Dim playerOpen As WMPLib.WindowsMediaPlayer = New WMPLib.WindowsMediaPlayer
      Dim mediaFile As WMPLib.IWMPMedia = playerOpen.newMedia(pathMedia)

      fileInfo.Duration = mediaFile.durationString

      fileInfo.Author = mediaFile.getItemInfo("Author")
      fileInfo.CurrentBitRate = mediaFile.getItemInfo("CurrentBitRate")
      fileInfo.FileSize = mediaFile.getItemInfo("FileSize")
      fileInfo.Is_Protected = mediaFile.getItemInfo("Is_Protected")
      fileInfo.SourceURL = mediaFile.getItemInfo("SourceURL")
      fileInfo.Title = mediaFile.getItemInfo("Title")
      fileInfo.WM_AlbumTitle = mediaFile.getItemInfo("WM/AlbumTitle")
      fileInfo.WM_Composer = mediaFile.getItemInfo("WM/Composer")
      fileInfo.WM_Genre = mediaFile.getItemInfo("WM/Genre")
      fileInfo.WM_Lyrics = mediaFile.getItemInfo("WM/Lyrics")
      fileInfo.WM_TrackNumber = mediaFile.getItemInfo("WM/TrackNumber")
      fileInfo.WM_Year = mediaFile.getItemInfo("WM/Year")

    Catch ex As Exception

      MessageBox.Show(ex.ToString)

    End Try

  End Sub 'ReadWMAInformation'

Bob
0
 
LVL 1

Author Comment

by:Trancedified
ID: 11956010
Wow getting closer:

So if I was to use your sub, ReadWMAInformation:
ReadWMAInformation("C:\Documents and Settings\Chris\My Documents\Chris\Work\WMA.NET\Samples\46920033.wma", ) <-----

What is inputted in the second parameter?

Chris
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11956069
This is what I have as a test:

    Dim fileInfo As WMAInformation = New WMAInformation

    ReadWMAInformation("C:\Documents and Settings\All Users\Documents\My Music\Sample Music\New Stories (Highway Blues).wma", fileInfo)

Bob
0
 
LVL 1

Author Comment

by:Trancedified
ID: 11957816
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11957867
 Public Function GetFileCreationTime(ByVal pathFile As String) As Date

    Dim dateCreation As Date

    Try

      Dim infoSelectedFile As System.IO.FileInfo = New System.IO.FileInfo(pathFile)

      dateCreation = infoSelectedFile.CreationTime

    Catch ex As Exception

      MessageBox.Show(ex.ToString)

    End Try

    Return dateCreation

  End Function 'GetFileCreationTime'

Bob
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql server, import complete table, using vb.net 9 53
VS 2015 is giving [No relevant source lines] 2 40
vb.net sendkey 4 19
Import a excel sheet in a grid 2 14
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question